GitHub

REST Client -- simple DSL for accessing HTTP and REST resources

Gem Downloads Build Status Code Climate Inline docs Join the chat at https://gitter.im/ruby-rest-client/community

A simple HTTP and REST client for Ruby, inspired by the Sinatra's microframework style of specifying actions: get, put, post, delete.

New mailing list

We have a new email list for announcements, hosted by Groups.io.

The old Librelist mailing list is defunct, as Librelist appears to be broken and not accepting new mail. The old archives are still up, but have been imported into the new list archives as well. http://librelist.com/browser/rest.client

Requirements

MRI Ruby 2.0 and newer are supported. Alternative interpreters compatible with 2.0+ should work as well.

Earlier Ruby versions such as 1.8.7, 1.9.2, and 1.9.3 are no longer supported. These versions no longer have any official support, and do not receive security updates.

The rest-client gem depends on these other gems for usage at runtime:

There are also several development dependencies. It's recommended to use bundler to manage these dependencies for hacking on rest-client.

Upgrading to rest-client 2.0 from 1.x

Users are encouraged to upgrade to rest-client 2.0, which cleans up a number of API warts and wrinkles, making rest-client generally more useful. Usage is largely compatible, so many applications will be able to upgrade with no changes.

Overview of significant changes:

  • requires Ruby >= 2.0
  • RestClient::Response objects are a subclass of String rather than a Frankenstein monster. And #body or #to_s return a true String object.
  • cleanup of exception classes, including new RestClient::Exceptions::Timeout
  • improvements to handling of redirects: responses and history are properly exposed
  • major changes to cookie support: cookie jars are used for browser-like behavior throughout
  • encoding: Content-Type charset response headers are used to automatically set the encoding of the response string
  • HTTP params: handling of GET/POST params is more consistent and sophisticated for deeply nested hash objects, and ParamsArray can be used to pass ordered params
  • improved proxy support with per-request proxy configuration, plus the ability to disable proxies set by environment variables
  • default request headers: rest-client sets Accept: */* and User-Agent: rest-client/...

See history.md for a more complete description of changes.

Usage: Raw URL

Basic usage:

require 'rest-client'
RestClient.get(url, headers={})
RestClient.post(url, payload, headers={})

In the high level helpers, only POST, PATCH, and PUT take a payload argument. To pass a payload with other HTTP verbs or to pass more advanced options, use RestClient::Request.execute instead.

More detailed examples:

"require 'rest-client' RestClient.get 'http://example.com/resource' RestClient.get 'http://example.com/resource', {params: {id: 50, 'foo' => 'bar'}} RestClient.get 'https://user:password@example.com/private/resource', {accept: :json} RestClient.post 'http://example.com/resource', {param1: 'one', nested: {param2: 'two'}} RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json} RestClient.delete 'http://example.com/resource' >> response = RestClient.get 'http://example.com/resource' => >> response.code => 200 >> response.cookies => {"Foo"=>"BAR", "QUUX"=>"QUUUUX"} >> response.headers => {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ... } >> response.body => "\n \n

Read the original on github.com ↗