Module RestClient
In: lib/restclient.rb
lib/restclient/abstract_response.rb
lib/restclient/exceptions.rb
lib/restclient/payload.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

<<   <<   <<   add_before_execution_proc   create_log   delete   get   head   log=   options   post   put   version  

Classes and Modules

Module RestClient::AbstractResponse
Module RestClient::Exceptions
Module RestClient::Payload
Module RestClient::Response
Module RestClient::ResponseForException
Class RestClient::Exception
Class RestClient::ExceptionWithResponse
Class RestClient::MaxRedirectsReached
Class RestClient::RawResponse
Class RestClient::Redirect
Class RestClient::Request
Class RestClient::RequestFailed
Class RestClient::Resource
Class RestClient::SSLCertificateNotVerified
Class RestClient::ServerBrokeConnection

Constants

STATUSES = {100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', #WebDAV 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', # http/1.1 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', #WebDAV 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', # http/1.1 304 => 'Not Modified', 305 => 'Use Proxy', # http/1.1 306 => 'Switch Proxy', # no longer used 307 => 'Temporary Redirect', # http/1.1 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Resource Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m A Teapot', 421 => 'Too Many Connections From This IP', 422 => 'Unprocessable Entity', #WebDAV 423 => 'Locked', #WebDAV 424 => 'Failed Dependency', #WebDAV 425 => 'Unordered Collection', #WebDAV 426 => 'Upgrade Required', 449 => 'Retry With', #Microsoft 450 => 'Blocked By Windows Parental Controls', #Microsoft 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', #WebDAV 509 => 'Bandwidth Limit Exceeded', #Apache 510 => 'Not Extended'}

Attributes

proxy  [RW] 

Public Class methods

Add a Proc to be called before each request in executed. The proc parameters will be the http request and the request params.

Create a log that respond to << like a logger param can be ‘stdout’, ‘stderr’, a string (then we will log to that file) or a logger (then we return it)

Setup the log for RestClient calls. Value should be a logger but can can be stdout, stderr, or a filename. You can also configure logging by the environment variable RESTCLIENT_LOG.

Public Instance methods

[Validate]