Module: RestClient

Module | RestClient
In: | lib/restclient.rb lib/restclient/exceptions.rb lib/restclient/mixin/response.rb lib/restclient/raw_response.rb lib/restclient/request.rb lib/restclient/resource.rb lib/restclient/response.rb

This module‘s static methods are the entry point for using the REST client.

      # GET
      xml = RestClient.get 'http://example.com/resource'
      jpg = RestClient.get 'http://example.com/resource', :accept => 'image/jpg'

      # authentication and SSL
      RestClient.get 'https://user:password@example.com/private/resource'

      # POST or PUT with a hash sends parameters as a urlencoded form body
      RestClient.post 'http://example.com/resource', :param1 => 'one'

      # nest hash parameters
      RestClient.post 'http://example.com/resource', :nested => { :param1 => 'one' }

      # POST and PUT with raw payloads
      RestClient.post 'http://example.com/resource', 'the post body', :content_type => 'text/plain'
      RestClient.post 'http://example.com/resource.xml', xml_doc
      RestClient.put 'http://example.com/resource.pdf', File.read('my.pdf'), :content_type => 'application/pdf'

      # DELETE
      RestClient.delete 'http://example.com/resource'

      # retreive the response http code and headers
      res = RestClient.get 'http://example.com/some.jpg'
      res.code                    # => 200
      res.headers[:content_type]  # => 'image/jpg'

      # HEAD
      RestClient.head('http://example.com').headers

To use with a proxy, just set RestClient.proxy to the proper http proxy:

      RestClient.proxy = "http://proxy.example.com/"

Or inherit the proxy from the environment:

      RestClient.proxy = ENV['http_proxy']

For live tests of RestClient, try using rest-test.heroku.com, which echoes back information about the rest call:

      >> RestClient.put 'http://rest-test.heroku.com/resource', :foo => 'baz'
      => "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"

### Methods

delete get head log= post put

### Classes and Modules

Module RestClient::Mixin
Class RestClient::Exception
Class RestClient::ExceptionWithResponse
Class RestClient::NotModified
Class RestClient::RawResponse
Class RestClient::Redirect
Class RestClient::Request
Class RestClient::RequestFailed
Class RestClient::RequestTimeout
Class RestClient::Resource
Class RestClient::ResourceNotFound
Class RestClient::Response
Class RestClient::ServerBrokeConnection
Class RestClient::Unauthorized

### Attributes

proxy | [RW] |

### Public Class methods

delete(url, headers={})
get(url, headers={})
head(url, headers={})
log=(log)

Print log of RestClient calls. Value can be stdout, stderr, or a filename. You can also configure logging by the environment variable RESTCLIENT_LOG.

post(url, payload, headers={})
put(url, payload, headers={})

[Validate]