HTTP Client – simple DSL for accessing HTTP resources

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

Usage: Raw URL

require 'http_client'

HttpClient.get ''
HttpClient.get 'https://user:[email protected]/private/resource' '', :param1 => 'one', :nested => { :param2 => 'two' }

HttpClient.delete ''

See HttpClient module docs for details.

Usage: ActiveResource-Style

resource = ''

private_resource = '', :user => 'adam', :password => 'secret', :timeout => 20, :open_timeout => 5
private_resource.put'pic.jpg'), :content_type => 'image/jpg'

See HttpClient::Resource module docs for details.

Usage: Resource Nesting

site ='')
site['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'

See HttpClient::Resource docs for details.


The http_client shell command gives an IRB session with HttpClient already loaded:

$ http_client
>> HttpClient.get ''

Specify a URL argument for get/post/put/delete on that resource:

$ http_client
>> put '/resource', 'data'

Add a user and password for authenticated resources:

$ http_client user pass
>> delete '/private/resource'

Create ~/.http_client for named sessions:

  url: http://localhost:4567
  url: http://localhost:9292
  username: user
  password: pass

Then invoke:

$ http_client private_site

Use as a one-off, curl-style:

$ http_client get > output_body

$ http_client put < input_body


Write calls to a log filename (can also be “stdout” or “stderr”):

HttpClient.log = '/tmp/http_client.log'

Or set an environment variable to avoid modifying the code:

$ HTTPCLIENT_LOG=stdout path/to/my/program

Either produces logs like this:

HttpClient.get "http://some/resource"
# => 200 OK | text/html 250 bytes
HttpClient.put "http://some/resource", "payload"
# => 401 Unauthorized | application/xml 340 bytes

Note that these logs are valid Ruby, so you can paste them into the http_client shell or a script to replay your sequence of http calls.


All calls to HttpClient, including Resources, will use the proxy specified by HttpClient.proxy:

HttpClient.proxy = ""
HttpClient.get "http://some/resource"
# => response from some/resource as proxied through

Often the proxy url is set in an environment variable, so you can do this to use whatever proxy the system is configured to use:

HttpClient.proxy = ENV['http_proxy']


Request and Response objects know about HTTP cookies, and will automatically extract and set headers for them as needed:

response = HttpClient.get ''
# => {"_applicatioN_session_id" => "1234"}

response2 =
  {:param1 => "foo"},
  {:cookies => {:session_id => "1234"}}
# ...response body

SSL Client Certificates
  :ssl_client_cert  =>"cert.pem")), 
  :ssl_client_key   =>"key.pem"), "passphrase, if any"),
  :ssl_ca_file      =>  "ca_certificate.pem", 
  :verify_ssl       =>  OpenSSL::SSL::VERIFY_PEER 

Self-signed certificates can be generated with the openssl command-line tool.


This library began its life as RestClient. Due to some changes and the desire to not conflict with the original library, Sevenwire forked and renamed it.

RestClient was written by Adam Wiggins (adam at heroku dot com)

RestClient Patches contributed by: Chris Anderson, Greg Borenstein, Ardekantur, Pedro Belo, Rafael Souza, Rick Olson, Aman Gupta, Blake Mizerany, Brian Donovan, Ivan Makfinsky, Marc-André Cournoyer, Coda Hale, Tetsuo Watanabe, Dusty Doris, Lennon Day-Reynolds, James Edward Gray II, Cyril Rohr, Juan Alvarez, and Adam Jacob

Released under the MIT License:

RestClient can be found at:

HttpClient can be found at: