[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7729":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":15,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":16,"rankGlobal":9,"rankLanguage":9,"license":17,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":20,"hasPages":18,"topics":21,"createdAt":9,"pushedAt":9,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":15,"starSnapshotCount":15,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},7729,"rest-client","rest-client\u002Frest-client","Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.","https:\u002F\u002Frubydoc.info\u002Fgithub\u002Frest-client\u002Frest-client\u002Fmaster",null,"Ruby",5216,930,98,90,0,64.91,"MIT License",false,"master",true,[],"2026-06-12 04:00:35","# REST Client -- simple DSL for accessing HTTP and REST resources\n\n[![Gem Downloads](https:\u002F\u002Fimg.shields.io\u002Fgem\u002Fdt\u002Frest-client.svg)](https:\u002F\u002Frubygems.org\u002Fgems\u002Frest-client)\n[![Build Status](https:\u002F\u002Ftravis-ci.org\u002Frest-client\u002Frest-client.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Frest-client\u002Frest-client)\n[![Code Climate](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Frest-client\u002Frest-client.svg)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Frest-client\u002Frest-client)\n[![Inline docs](http:\u002F\u002Finch-ci.org\u002Fgithub\u002Frest-client\u002Frest-client.svg?branch=master)](http:\u002F\u002Fwww.rubydoc.info\u002Fgithub\u002Frest-client\u002Frest-client\u002Fmaster)\n[![Join the chat at https:\u002F\u002Fgitter.im\u002Fruby-rest-client\u002Fcommunity](https:\u002F\u002Fbadges.gitter.im\u002Fruby-rest-client\u002Fcommunity.svg)](https:\u002F\u002Fgitter.im\u002Fruby-rest-client\u002Fcommunity?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nA simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style\nof specifying actions: get, put, post, delete.\n\n* Main page: https:\u002F\u002Fgithub.com\u002Frest-client\u002Frest-client\n* Mailing list: https:\u002F\u002Fgroups.io\u002Fg\u002Frest-client\n\n### New mailing list\n\nWe have a new email list for announcements, hosted by Groups.io.\n\n* Subscribe on the web: https:\u002F\u002Fgroups.io\u002Fg\u002Frest-client\n\n* Subscribe by sending an email: mailto:rest-client+subscribe@groups.io\n\n* Open discussion subgroup: https:\u002F\u002Fgroups.io\u002Fg\u002Frest-client+discuss\n\nThe old Librelist mailing list is *defunct*, as Librelist appears to be broken\nand not accepting new mail. The old archives are still up, but have been\nimported into the new list archives as well.\nhttp:\u002F\u002Flibrelist.com\u002Fbrowser\u002Frest.client\n\n## Requirements\n\nMRI Ruby 2.0 and newer are supported. Alternative interpreters compatible with\n2.0+ should work as well.\n\nEarlier Ruby versions such as 1.8.7, 1.9.2, and 1.9.3 are no longer supported. These\nversions no longer have any official support, and do not receive security\nupdates.\n\nThe rest-client gem depends on these other gems for usage at runtime:\n\n* [mime-types](http:\u002F\u002Frubygems.org\u002Fgems\u002Fmime-types)\n* [netrc](http:\u002F\u002Frubygems.org\u002Fgems\u002Fnetrc)\n* [http-accept](https:\u002F\u002Frubygems.org\u002Fgems\u002Fhttp-accept)\n* [http-cookie](https:\u002F\u002Frubygems.org\u002Fgems\u002Fhttp-cookie)\n\nThere are also several development dependencies. It's recommended to use\n[bundler](http:\u002F\u002Fbundler.io\u002F) to manage these dependencies for hacking on\nrest-client.\n\n### Upgrading to rest-client 2.0 from 1.x\n\nUsers are encouraged to upgrade to rest-client 2.0, which cleans up a number of\nAPI warts and wrinkles, making rest-client generally more useful. Usage is\nlargely compatible, so many applications will be able to upgrade with no\nchanges.\n\nOverview of significant changes:\n\n* requires Ruby >= 2.0\n* `RestClient::Response` objects are a subclass of `String` rather than a\n  Frankenstein monster. And `#body` or `#to_s` return a true `String` object.\n* cleanup of exception classes, including new `RestClient::Exceptions::Timeout`\n* improvements to handling of redirects: responses and history are properly\n  exposed\n* major changes to cookie support: cookie jars are used for browser-like\n  behavior throughout\n* encoding: Content-Type charset response headers are used to automatically set\n  the encoding of the response string\n* HTTP params: handling of GET\u002FPOST params is more consistent and sophisticated\n  for deeply nested hash objects, and `ParamsArray` can be used to pass ordered\n  params\n* improved proxy support with per-request proxy configuration, plus the ability\n  to disable proxies set by environment variables\n* default request headers: rest-client sets `Accept: *\u002F*` and\n  `User-Agent: rest-client\u002F...`\n\nSee [history.md](.\u002Fhistory.md) for a more complete description of changes.\n\n## Usage: Raw URL\n\nBasic usage:\n\n```ruby\nrequire 'rest-client'\n\nRestClient.get(url, headers={})\n\nRestClient.post(url, payload, headers={})\n```\n\nIn the high level helpers, only POST, PATCH, and PUT take a payload argument.\nTo pass a payload with other HTTP verbs or to pass more advanced options, use\n`RestClient::Request.execute` instead.\n\nMore detailed examples:\n\n```ruby\nrequire 'rest-client'\n\nRestClient.get 'http:\u002F\u002Fexample.com\u002Fresource'\n\nRestClient.get 'http:\u002F\u002Fexample.com\u002Fresource', {params: {id: 50, 'foo' => 'bar'}}\n\nRestClient.get 'https:\u002F\u002Fuser:password@example.com\u002Fprivate\u002Fresource', {accept: :json}\n\nRestClient.post 'http:\u002F\u002Fexample.com\u002Fresource', {param1: 'one', nested: {param2: 'two'}}\n\nRestClient.post \"http:\u002F\u002Fexample.com\u002Fresource\", {'x' => 1}.to_json, {content_type: :json, accept: :json}\n\nRestClient.delete 'http:\u002F\u002Fexample.com\u002Fresource'\n\n>> response = RestClient.get 'http:\u002F\u002Fexample.com\u002Fresource'\n=> \u003CRestClient::Response 200 \"\u003C!doctype h...\">\n>> response.code\n=> 200\n>> response.cookies\n=> {\"Foo\"=>\"BAR\", \"QUUX\"=>\"QUUUUX\"}\n>> response.headers\n=> {:content_type=>\"text\u002Fhtml; charset=utf-8\", :cache_control=>\"private\" ... }\n>> response.body\n=> \"\u003C!doctype html>\\n\u003Chtml>\\n\u003Chead>\\n    \u003Ctitle>Example Domain\u003C\u002Ftitle>\\n\\n ...\"\n\nRestClient.post( url,\n  {\n    :transfer => {\n      :path => '\u002Ffoo\u002Fbar',\n      :owner => 'that_guy',\n      :group => 'those_guys'\n    },\n     :upload => {\n      :file => File.new(path, 'rb')\n    }\n  })\n```\n## Passing advanced options\n\nThe top level helper methods like RestClient.get accept a headers hash as\ntheir last argument and don't allow passing more complex options. But these\nhelpers are just thin wrappers around `RestClient::Request.execute`.\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            timeout: 10)\n\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            ssl_ca_file: 'myca.pem',\n                            ssl_ciphers: 'AESGCM:!aNULL')\n```\nYou can also use this to pass a payload for HTTP verbs like DELETE, where the\n`RestClient.delete` helper doesn't accept a payload.\n\n```ruby\nRestClient::Request.execute(method: :delete, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            payload: 'foo', headers: {myheader: 'bar'})\n```\n\nDue to unfortunate choices in the original API, the params used to populate the\nquery string are actually taken out of the headers hash. So if you want to pass\nboth the params hash and more complex options, use the special key\n`:params` in the headers hash. This design may change in a future major\nrelease.\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            timeout: 10, headers: {params: {foo: 'bar'}})\n\n➔ GET http:\u002F\u002Fexample.com\u002Fresource?foo=bar\n```\n\n## Multipart\n\nYeah, that's right!  This does multipart sends for you!\n\n```ruby\nRestClient.post '\u002Fdata', :myfile => File.new(\"\u002Fpath\u002Fto\u002Fimage.jpg\", 'rb')\n```\n\nThis does two things for you:\n\n- Auto-detects that you have a File value sends it as multipart\n- Auto-detects the mime of the file and sets it in the HEAD of the payload for each entry\n\nIf you are sending params that do not contain a File object but the payload needs to be multipart then:\n\n```ruby\nRestClient.post '\u002Fdata', {:foo => 'bar', :multipart => true}\n```\n\n## Usage: ActiveResource-Style\n\n```ruby\nresource = RestClient::Resource.new 'http:\u002F\u002Fexample.com\u002Fresource'\nresource.get\n\nprivate_resource = RestClient::Resource.new 'https:\u002F\u002Fexample.com\u002Fprivate\u002Fresource', 'user', 'pass'\nprivate_resource.put File.read('pic.jpg'), :content_type => 'image\u002Fjpg'\n```\n\nSee RestClient::Resource module docs for details.\n\n## Usage: Resource Nesting\n\n```ruby\nsite = RestClient::Resource.new('http:\u002F\u002Fexample.com')\nsite['posts\u002F1\u002Fcomments'].post 'Good article.', :content_type => 'text\u002Fplain'\n```\nSee `RestClient::Resource` docs for details.\n\n## Exceptions (see http:\u002F\u002Fwww.w3.org\u002FProtocols\u002Frfc2616\u002Frfc2616-sec10.html)\n\n- for result codes between `200` and `207`, a `RestClient::Response` will be returned\n- for result codes `301`, `302` or `307`, the redirection will be followed if the request is a `GET` or a `HEAD`\n- for result code `303`, the redirection will be followed and the request transformed into a `GET`\n- for other cases, a `RestClient::ExceptionWithResponse` holding the Response will be raised; a specific exception class will be thrown for known error codes\n- call `.response` on the exception to get the server's response\n\n```ruby\n>> RestClient.get 'http:\u002F\u002Fexample.com\u002Fnonexistent'\nException: RestClient::NotFound: 404 Not Found\n\n>> begin\n     RestClient.get 'http:\u002F\u002Fexample.com\u002Fnonexistent'\n   rescue RestClient::ExceptionWithResponse => e\n     e.response\n   end\n=> \u003CRestClient::Response 404 \"\u003C!doctype h...\">\n```\n\n### Other exceptions\n\nWhile most exceptions have been collected under `RestClient::RequestFailed` aka\n`RestClient::ExceptionWithResponse`, there are a few quirky exceptions that\nhave been kept for backwards compatibility.\n\nRestClient will propagate up exceptions like socket errors without modification:\n\n```ruby\n>> RestClient.get 'http:\u002F\u002Flocalhost:12345'\nException: Errno::ECONNREFUSED: Connection refused - connect(2) for \"localhost\" port 12345\n```\n\nRestClient handles a few specific error cases separately in order to give\nbetter error messages. These will hopefully be cleaned up in a future major\nrelease.\n\n`RestClient::ServerBrokeConnection` is translated from `EOFError` to give a\nbetter error message.\n\n`RestClient::SSLCertificateNotVerified` is raised when HTTPS validation fails.\nOther `OpenSSL::SSL::SSLError` errors are raised as is.\n\n### Redirection\n\nBy default, rest-client will follow HTTP 30x redirection requests.\n\n__New in 2.0:__ `RestClient::Response` exposes a `#history` method that returns\na list of each response received in a redirection chain.\n\n```ruby\n>> r = RestClient.get('http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F2')\n=> \u003CRestClient::Response 200 \"{\\n  \\\"args\\\":...\">\n\n# see each response in the redirect chain\n>> r.history\n=> [\u003CRestClient::Response 302 \"\u003C!DOCTYPE H...\">, \u003CRestClient::Response 302 \"\">]\n\n# see each requested URL\n>> r.request.url\n=> \"http:\u002F\u002Fhttpbin.org\u002Fget\"\n>> r.history.map {|x| x.request.url}\n=> [\"http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F2\", \"http:\u002F\u002Fhttpbin.org\u002Frelative-redirect\u002F1\"]\n```\n\n#### Manually following redirection\n\nTo disable automatic redirection, set `:max_redirects => 0`.\n\n__New in 2.0:__ Prior versions of rest-client would raise\n`RestClient::MaxRedirectsReached`, with no easy way to access the server's\nresponse. In 2.0, rest-client raises the normal\n`RestClient::ExceptionWithResponse` as it would with any other non-HTTP-20x\nresponse.\n\n```ruby\n>> RestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F1')\n=> RestClient::Response 200 \"{\\n  \"args\":...\"\n\n>> RestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F1', max_redirects: 0)\nRestClient::Found: 302 Found\n```\n\nTo manually follow redirection, you can call `Response#follow_redirection`. Or\nyou could of course inspect the result and choose custom behavior.\n\n```ruby\n>> RestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F1', max_redirects: 0)\nRestClient::Found: 302 Found\n>> begin\n       RestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fhttpbin.org\u002Fredirect\u002F1', max_redirects: 0)\n   rescue RestClient::ExceptionWithResponse => err\n   end\n>> err\n=> #\u003CRestClient::Found: 302 Found>\n>> err.response\n=> RestClient::Response 302 \"\u003C!DOCTYPE H...\"\n>> err.response.headers[:location]\n=> \"\u002Fget\"\n>> err.response.follow_redirection\n=> RestClient::Response 200 \"{\\n  \"args\":...\"\n```\n\n## Result handling\n\nThe result of a `RestClient::Request` is a `RestClient::Response` object.\n\n__New in 2.0:__ `RestClient::Response` objects are now a subclass of `String`.\nPreviously, they were a real String object with response functionality mixed\nin, which was very confusing to work with.\n\nResponse objects have several useful methods. (See the class rdoc for more details.)\n\n- `Response#code`: The HTTP response code\n- `Response#body`: The response body as a string. (AKA .to_s)\n- `Response#headers`: A hash of HTTP response headers\n- `Response#raw_headers`: A hash of HTTP response headers as unprocessed arrays\n- `Response#cookies`: A hash of HTTP cookies set by the server\n- `Response#cookie_jar`: \u003Cem>New in 1.8\u003C\u002Fem> An HTTP::CookieJar of cookies\n- `Response#request`: The RestClient::Request object used to make the request\n- `Response#history`: \u003Cem>New in 2.0\u003C\u002Fem> If redirection was followed, a list of prior Response objects\n\n```ruby\nRestClient.get('http:\u002F\u002Fexample.com')\n➔ \u003CRestClient::Response 200 \"\u003C!doctype h...\">\n\nbegin\n RestClient.get('http:\u002F\u002Fexample.com\u002Fnotfound')\nrescue RestClient::ExceptionWithResponse => err\n  err.response\nend\n➔ \u003CRestClient::Response 404 \"\u003C!doctype h...\">\n```\n\n### Response callbacks, error handling\n\nA block can be passed to the RestClient method. This block will then be called with the Response.\nResponse.return! can be called to invoke the default response's behavior.\n\n```ruby\n# Don't raise exceptions but return the response\n>> RestClient.get('http:\u002F\u002Fexample.com\u002Fnonexistent') {|response, request, result| response }\n=> \u003CRestClient::Response 404 \"\u003C!doctype h...\">\n```\n\n```ruby\n# Manage a specific error code\nRestClient.get('http:\u002F\u002Fexample.com\u002Fresource') { |response, request, result, &block|\n  case response.code\n  when 200\n    p \"It worked !\"\n    response\n  when 423\n    raise SomeCustomExceptionIfYouWant\n  else\n    response.return!(&block)\n  end\n}\n```\n\nBut note that it may be more straightforward to use exceptions to handle\ndifferent HTTP error response cases:\n\n```ruby\nbegin\n  resp = RestClient.get('http:\u002F\u002Fexample.com\u002Fresource')\nrescue RestClient::Unauthorized, RestClient::Forbidden => err\n  puts 'Access denied'\n  return err.response\nrescue RestClient::ImATeapot => err\n  puts 'The server is a teapot! # RFC 2324'\n  return err.response\nelse\n  puts 'It worked!'\n  return resp\nend\n```\n\nFor GET and HEAD requests, rest-client automatically follows redirection. For\nother HTTP verbs, call `.follow_redirection` on the response object (works both\nin block form and in exception form).\n\n```ruby\n# Follow redirections for all request types and not only for get and head\n# RFC : \"If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD,\n#        the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user,\n#        since this might change the conditions under which the request was issued.\"\n\n# block style\nRestClient.post('http:\u002F\u002Fexample.com\u002Fredirect', 'body') { |response, request, result|\n  case response.code\n  when 301, 302, 307\n    response.follow_redirection\n  else\n    response.return!\n  end\n}\n\n# exception style by explicit classes\nbegin\n  RestClient.post('http:\u002F\u002Fexample.com\u002Fredirect', 'body')\nrescue RestClient::MovedPermanently,\n       RestClient::Found,\n       RestClient::TemporaryRedirect => err\n  err.response.follow_redirection\nend\n\n# exception style by response code\nbegin\n  RestClient.post('http:\u002F\u002Fexample.com\u002Fredirect', 'body')\nrescue RestClient::ExceptionWithResponse => err\n  case err.http_code\n  when 301, 302, 307\n    err.response.follow_redirection\n  else\n    raise\n  end\nend\n```\n\n## Non-normalized URIs\n\nIf you need to normalize URIs, e.g. to work with International Resource Identifiers (IRIs),\nuse the Addressable gem (https:\u002F\u002Fgithub.com\u002Fsporkmonger\u002Faddressable\u002F) in your code:\n\n```ruby\n  require 'addressable\u002Furi'\n  RestClient.get(Addressable::URI.parse(\"http:\u002F\u002Fwww.詹姆斯.com\u002F\").normalize.to_str)\n```\n\n## Lower-level access\n\nFor cases not covered by the general API, you can use the `RestClient::Request` class, which provides a lower-level API.\n\nYou can:\n\n- specify ssl parameters\n- override cookies\n- manually handle the response (e.g. to operate on it as a stream rather than reading it all into memory)\n\nSee `RestClient::Request`'s documentation for more information.\n\n### Streaming request payload\n\nRestClient will try to stream any file-like payload rather than reading it into\nmemory. This happens through `RestClient::Payload::Streamed`, which is\nautomatically called internally by `RestClient::Payload.generate` on anything\nwith a `read` method.\n\n```ruby\n>> r = RestClient.put('http:\u002F\u002Fhttpbin.org\u002Fput', File.open('\u002Ftmp\u002Ffoo.txt', 'r'),\n                      content_type: 'text\u002Fplain')\n=> \u003CRestClient::Response 200 \"{\\n  \\\"args\\\":...\">\n```\n\nIn Multipart requests, RestClient will also stream file handles passed as Hash\n(or __new in 2.1__ ParamsArray).\n\n```ruby\n>> r = RestClient.put('http:\u002F\u002Fhttpbin.org\u002Fput',\n                      {file_a: File.open('a.txt', 'r'),\n                       file_b: File.open('b.txt', 'r')})\n=> \u003CRestClient::Response 200 \"{\\n  \\\"args\\\":...\">\n\n# received by server as two file uploads with multipart\u002Fform-data\n>> JSON.parse(r)['files'].keys\n=> ['file_a', 'file_b']\n```\n\n### Streaming responses\n\nNormally, when you use `RestClient.get` or the lower level\n`RestClient::Request.execute method: :get` to retrieve data, the entire\nresponse is buffered in memory and returned as the response to the call.\n\nHowever, if you are retrieving a large amount of data, for example a Docker\nimage, an iso, or any other large file, you may want to stream the response\ndirectly to disk rather than loading it in memory. If you have a very large\nfile, it may become *impossible* to load it into memory.\n\nThere are two main ways to do this:\n\n#### `raw_response`, saves into Tempfile\n\nIf you pass `raw_response: true` to `RestClient::Request.execute`, it will save\nthe response body to a temporary file (using `Tempfile`) and return a\n`RestClient::RawResponse` object rather than a `RestClient::Response`.\n\nNote that the tempfile created by `Tempfile.new` will be in `Dir.tmpdir`\n(usually `\u002Ftmp\u002F`), which you can override to store temporary files in a\ndifferent location. This file will be unlinked when it is dereferenced.\n\nIf logging is enabled, this will also print download progress.\n__New in 2.1:__ Customize the interval with `:stream_log_percent` (defaults to\n10 for printing a message every 10% complete).\n\nFor example:\n\n```ruby\n>> raw = RestClient::Request.execute(\n           method: :get,\n           url: 'http:\u002F\u002Freleases.ubuntu.com\u002F16.04.2\u002Fubuntu-16.04.2-desktop-amd64.iso',\n           raw_response: true)\n=> \u003CRestClient::RawResponse @code=200, @file=#\u003CTempfile:\u002Ftmp\u002Frest-client.20170522-5346-1pptjm1>, @request=\u003CRestClient::Request @method=\"get\", @url=\"http:\u002F\u002Freleases.ubuntu.com\u002F16.04.2\u002Fubuntu-16.04.2-desktop-amd64.iso\">>\n>> raw.file.size\n=> 1554186240\n>> raw.file.path\n=> \"\u002Ftmp\u002Frest-client.20170522-5346-1pptjm1\"\nraw.file.path\n=> \"\u002Ftmp\u002Frest-client.20170522-5346-1pptjm1\"\n\n>> require 'digest\u002Fsha1'\n>> Digest::SHA1.file(raw.file.path).hexdigest\n=> \"4375b73e3a1aa305a36320ffd7484682922262b3\"\n```\n\n#### `block_response`, receives raw Net::HTTPResponse\n\nIf you want to stream the data from the response to a file as it comes, rather\nthan entirely in memory, you can also pass `RestClient::Request.execute` a\nparameter `:block_response` to which you pass a block\u002Fproc. This block receives\nthe raw unmodified Net::HTTPResponse object from Net::HTTP, which you can use\nto stream directly to a file as each chunk is received.\n\nNote that this bypasses all the usual HTTP status code handling, so you will\nwant to do you own checking for HTTP 20x response codes, redirects, etc.\n\nThe following is an example:\n\n````ruby\nFile.open('\u002Fsome\u002Foutput\u002Ffile', 'w') {|f|\n  block = proc { |response|\n    response.read_body do |chunk|\n      f.write chunk\n    end\n  }\n  RestClient::Request.execute(method: :get,\n                              url: 'http:\u002F\u002Fexample.com\u002Fsome\u002Freally\u002Fbig\u002Ffile.img',\n                              block_response: block)\n}\n````\n\n## Shell\n\nThe restclient shell command gives an IRB session with RestClient already loaded:\n\n```ruby\n$ restclient\n>> RestClient.get 'http:\u002F\u002Fexample.com'\n```\n\nSpecify a URL argument for get\u002Fpost\u002Fput\u002Fdelete on that resource:\n\n```ruby\n$ restclient http:\u002F\u002Fexample.com\n>> put '\u002Fresource', 'data'\n```\n\nAdd a user and password for authenticated resources:\n\n```ruby\n$ restclient https:\u002F\u002Fexample.com user pass\n>> delete '\u002Fprivate\u002Fresource'\n```\n\nCreate ~\u002F.restclient for named sessions:\n\n```ruby\n  sinatra:\n    url: http:\u002F\u002Flocalhost:4567\n  rack:\n    url: http:\u002F\u002Flocalhost:9292\n  private_site:\n    url: http:\u002F\u002Fexample.com\n    username: user\n    password: pass\n```\n\nThen invoke:\n\n```ruby\n$ restclient private_site\n```\n\nUse as a one-off, curl-style:\n\n```ruby\n$ restclient get http:\u002F\u002Fexample.com\u002Fresource > output_body\n\n$ restclient put http:\u002F\u002Fexample.com\u002Fresource \u003C input_body\n```\n\n## Logging\n\nTo enable logging globally you can:\n\n- set RestClient.log with a Ruby Logger\n\n```ruby\nRestClient.log = STDOUT\n```\n\n- or set an environment variable to avoid modifying the code (in this case you can use a file name, \"stdout\" or \"stderr\"):\n\n```ruby\n$ RESTCLIENT_LOG=stdout path\u002Fto\u002Fmy\u002Fprogram\n```\n\nYou can also set individual loggers when instantiating a Resource or making an\nindividual request:\n\n```ruby\nresource = RestClient::Resource.new 'http:\u002F\u002Fexample.com\u002Fresource', log: Logger.new(STDOUT)\n```\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Ffoo', log: Logger.new(STDERR))\n```\n\nAll options produce logs like this:\n\n```ruby\nRestClient.get \"http:\u002F\u002Fsome\u002Fresource\"\n# => 200 OK | text\u002Fhtml 250 bytes\nRestClient.put \"http:\u002F\u002Fsome\u002Fresource\", \"payload\"\n# => 401 Unauthorized | application\u002Fxml 340 bytes\n```\n\nNote that these logs are valid Ruby, so you can paste them into the `restclient`\nshell or a script to replay your sequence of rest calls.\n\n## Proxy\n\nAll calls to RestClient, including Resources, will use the proxy specified by\n`RestClient.proxy`:\n\n```ruby\nRestClient.proxy = \"http:\u002F\u002Fproxy.example.com\u002F\"\nRestClient.get \"http:\u002F\u002Fsome\u002Fresource\"\n# => response from some\u002Fresource as proxied through proxy.example.com\n```\n\nOften the proxy URL is set in an environment variable, so you can do this to\nuse whatever proxy the system is configured to use:\n\n```ruby\n  RestClient.proxy = ENV['http_proxy']\n```\n\n__New in 2.0:__ Specify a per-request proxy by passing the :proxy option to\nRestClient::Request. This will override any proxies set by environment variable\nor by the global `RestClient.proxy` value.\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com',\n                            proxy: 'http:\u002F\u002Fproxy.example.com')\n# => single request proxied through the proxy\n```\n\nThis can be used to disable the use of a proxy for a particular request.\n\n```ruby\nRestClient.proxy = \"http:\u002F\u002Fproxy.example.com\u002F\"\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com', proxy: nil)\n# => single request sent without a proxy\n```\n\n## Query parameters\n\nRest-client can render a hash as HTTP query parameters for GET\u002FHEAD\u002FDELETE\nrequests or as HTTP post data in `x-www-form-urlencoded` format for POST\nrequests.\n\n__New in 2.0:__ Even though there is no standard specifying how this should\nwork, rest-client follows a similar convention to the one used by Rack \u002F Rails\nservers for handling arrays, nested hashes, and null values.\n\nThe implementation in\n[.\u002Flib\u002Frest-client\u002Futils.rb](RestClient::Utils.encode_query_string)\nclosely follows\n[Rack::Utils.build_nested_query](http:\u002F\u002Fwww.rubydoc.info\u002Fgems\u002Frack\u002FRack\u002FUtils#build_nested_query-class_method),\nbut treats empty arrays and hashes as `nil`. (Rack drops them entirely, which\nis confusing behavior.)\n\nIf you don't like this behavior and want more control, just serialize params\nyourself (e.g. with `URI.encode_www_form`) and add the query string to the URL\ndirectly for GET parameters or pass the payload as a string for POST requests.\n\nBasic GET params:\n```ruby\nRestClient.get('https:\u002F\u002Fhttpbin.org\u002Fget', params: {foo: 'bar', baz: 'qux'})\n# GET \"https:\u002F\u002Fhttpbin.org\u002Fget?foo=bar&baz=qux\"\n```\n\nBasic `x-www-form-urlencoded` POST params:\n```ruby\n>> r = RestClient.post('https:\u002F\u002Fhttpbin.org\u002Fpost', {foo: 'bar', baz: 'qux'})\n# POST \"https:\u002F\u002Fhttpbin.org\u002Fpost\", data: \"foo=bar&baz=qux\"\n=> \u003CRestClient::Response 200 \"{\\n  \\\"args\\\":...\">\n>> JSON.parse(r.body)\n=> {\"args\"=>{},\n    \"data\"=>\"\",\n    \"files\"=>{},\n    \"form\"=>{\"baz\"=>\"qux\", \"foo\"=>\"bar\"},\n    \"headers\"=>\n    {\"Accept\"=>\"*\u002F*\",\n        \"Accept-Encoding\"=>\"gzip, deflate\",\n        \"Content-Length\"=>\"15\",\n        \"Content-Type\"=>\"application\u002Fx-www-form-urlencoded\",\n        \"Host\"=>\"httpbin.org\"},\n    \"json\"=>nil,\n    \"url\"=>\"https:\u002F\u002Fhttpbin.org\u002Fpost\"}\n```\n\nJSON payload: rest-client does not speak JSON natively, so serialize your\npayload to a string before passing it to rest-client.\n```ruby\n>> payload = {'name' => 'newrepo', 'description': 'A new repo'}\n>> RestClient.post('https:\u002F\u002Fapi.github.com\u002Fuser\u002Frepos', payload.to_json, content_type: :json)\n=> \u003CRestClient::Response 201 \"{\\\"id\\\":75149...\">\n```\n\nAdvanced GET params (arrays):\n```ruby\n>> r = RestClient.get('https:\u002F\u002Fhttp-params.herokuapp.com\u002Fget', params: {foo: [1,2,3]})\n# GET \"https:\u002F\u002Fhttp-params.herokuapp.com\u002Fget?foo[]=1&foo[]=2&foo[]=3\"\n=> \u003CRestClient::Response 200 \"Method: GET...\">\n>> puts r.body\nquery_string: \"foo[]=1&foo[]=2&foo[]=3\"\ndecoded:      \"foo[]=1&foo[]=2&foo[]=3\"\n\nGET:\n  {\"foo\"=>[\"1\", \"2\", \"3\"]}\n```\n\nAdvanced GET params (nested hashes):\n```ruby\n>> r = RestClient.get('https:\u002F\u002Fhttp-params.herokuapp.com\u002Fget', params: {outer: {foo: 123, bar: 456}})\n# GET \"https:\u002F\u002Fhttp-params.herokuapp.com\u002Fget?outer[foo]=123&outer[bar]=456\"\n=> \u003CRestClient::Response 200 \"Method: GET...\">\n>> puts r.body\n...\nquery_string: \"outer[foo]=123&outer[bar]=456\"\ndecoded:      \"outer[foo]=123&outer[bar]=456\"\n\nGET:\n  {\"outer\"=>{\"foo\"=>\"123\", \"bar\"=>\"456\"}}\n```\n\n__New in 2.0:__ The new `RestClient::ParamsArray` class allows callers to\nprovide ordering even to structured parameters. This is useful for unusual\ncases where the server treats the order of parameters as significant or you\nwant to pass a particular key multiple times.\n\nMultiple fields with the same name using ParamsArray:\n```ruby\n>> RestClient.get('https:\u002F\u002Fhttpbin.org\u002Fget', params:\n                  RestClient::ParamsArray.new([[:foo, 1], [:foo, 2]]))\n# GET \"https:\u002F\u002Fhttpbin.org\u002Fget?foo=1&foo=2\"\n```\n\nNested ParamsArray:\n```ruby\n>> RestClient.get('https:\u002F\u002Fhttpbin.org\u002Fget', params:\n                  {foo: RestClient::ParamsArray.new([[:a, 1], [:a, 2]])})\n# GET \"https:\u002F\u002Fhttpbin.org\u002Fget?foo[a]=1&foo[a]=2\"\n```\n\n## Headers\n\nRequest headers can be set by passing a ruby hash containing keys and values\nrepresenting header names and values:\n\n```ruby\n# GET request with modified headers\nRestClient.get 'http:\u002F\u002Fexample.com\u002Fresource', {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}\n\n# POST request with modified headers\nRestClient.post 'http:\u002F\u002Fexample.com\u002Fresource', {:foo => 'bar', :baz => 'qux'}, {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}\n\n# DELETE request with modified headers\nRestClient.delete 'http:\u002F\u002Fexample.com\u002Fresource', {:Authorization => 'Bearer cT0febFoD5lxAlNAXHo6g'}\n```\n\n## Timeouts\n\nBy default the timeout for a request is 60 seconds. Timeouts for your request can\nbe adjusted by setting the `timeout:` to the number of seconds that you would like\nthe request to wait. Setting `timeout:` will override both `read_timeout:` and `open_timeout:`.\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            timeout: 120)\n```\n\nAdditionally, you can set `read_timeout:` and `open_timeout:` separately.\n\n```ruby\nRestClient::Request.execute(method: :get, url: 'http:\u002F\u002Fexample.com\u002Fresource',\n                            read_timeout: 120, open_timeout: 240)\n```\n\n## Cookies\n\nRequest and Response objects know about HTTP cookies, and will automatically\nextract and set headers for them as needed:\n\n```ruby\nresponse = RestClient.get 'http:\u002F\u002Fexample.com\u002Faction_which_sets_session_id'\nresponse.cookies\n# => {\"_applicatioN_session_id\" => \"1234\"}\n\nresponse2 = RestClient.post(\n  'http:\u002F\u002Flocalhost:3000\u002F',\n  {:param1 => \"foo\"},\n  {:cookies => {:session_id => \"1234\"}}\n)\n# ...response body\n```\n### Full cookie jar support (new in 1.8)\n\nThe original cookie implementation was very naive and ignored most of the\ncookie RFC standards.\n__New in 1.8__:  An HTTP::CookieJar of cookies\n\nResponse objects now carry a cookie_jar method that exposes an HTTP::CookieJar\nof cookies, which supports full standards compliant behavior.\n\n## SSL\u002FTLS support\n\nVarious options are supported for configuring rest-client's TLS settings. By\ndefault, rest-client will verify certificates using the system's CA store on\nall platforms. (This is intended to be similar to how browsers behave.) You can\nspecify an :ssl_ca_file, :ssl_ca_path, or :ssl_cert_store to customize the\ncertificate authorities accepted.\n\n### SSL Client Certificates\n\n```ruby\nRestClient::Resource.new(\n  'https:\u002F\u002Fexample.com',\n  :ssl_client_cert  =>  OpenSSL::X509::Certificate.new(File.read(\"cert.pem\")),\n  :ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read(\"key.pem\"), \"passphrase, if any\"),\n  :ssl_ca_file      =>  \"ca_certificate.pem\",\n  :verify_ssl       =>  OpenSSL::SSL::VERIFY_PEER\n).get\n```\nSelf-signed certificates can be generated with the openssl command-line tool.\n\n## Hook\n\nRestClient.add_before_execution_proc add a Proc to be called before each execution.\nIt's handy if you need direct access to the HTTP request.\n\nExample:\n\n```ruby\n# Add oauth support using the oauth gem\nrequire 'oauth'\naccess_token = ...\n\nRestClient.add_before_execution_proc do |req, params|\n  access_token.sign! req\nend\n\nRestClient.get 'http:\u002F\u002Fexample.com'\n```\n\n## More\n\nNeed caching, more advanced logging or any ability provided by Rack middleware?\n\nHave a look at rest-client-components: http:\u002F\u002Fgithub.com\u002Fcrohr\u002Frest-client-components\n\n## Credits\n| | |\n|-------------------------|---------------------------------------------------------|\n| **REST Client Team**    | Andy Brody                                              |\n| **Creator**             | Adam Wiggins                                            |\n| **Maintainers Emeriti** | Lawrence Leonard Gilbert, Matthew Manning, Julien Kirch |\n| **Major contributions** | Blake Mizerany, Julien Kirch                            |\n\nA great many generous folks have contributed features and patches.\nSee AUTHORS for the full list.\n\n## Legal\n\nReleased under the MIT License: https:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT\n\nPhoto of the International Space Station was produced by NASA and is in the\npublic domain.\n\nCode for reading Windows root certificate store derived from work by Puppet;\nused under terms of the Apache License, Version 2.0.\n","rest-client 是一个为 Ruby 设计的简单 HTTP 和 REST 客户端，其语法灵感来源于 Sinatra 微框架的动作指定方式。它支持 GET、PUT、POST 和 DELETE 等标准 HTTP 方法，并且能够处理包括 JSON 在内的多种数据格式。该项目采用了直观易用的设计理念，使得开发者可以轻松地发起网络请求并处理响应，而无需深入理解底层实现细节。此外，通过继承 String 类来表示响应体，rest-client 提供了更加一致和自然的数据访问方式。适用于需要快速集成 RESTful API 的 Ruby 应用场景，如后端服务间通信、第三方 API 调用等。",2,"2026-06-11 03:14:05","top_language"]