Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Common interface for Ruby's HTTP clients
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
autotest
lib
spec
.gitignore
.rspec
Gemfile
README.rdoc
Rakefile
httpi.gemspec

README.rdoc

HTTPI

HTTPI provides a common interface for different HTTP libraries.

Installation

The gem is available through Rubygems and can be installed via:

$ gem install httpi

Supported libraries

Getting started

To get started, simply create a new HTTPI::Client:

client = HTTPI::Client.new :curb

Notice that when you're not passing a library to use, HTTPI will default to use the HTTPClient library:

HTTPI::Adapter.use  # => :httpclient

Changing the default is fairly easy:

HTTPI::Adapter.use = :curb

Settings

#headers

Accessor for the HTTP request headers:

client.headers = { "Accept-Encoding" => "gzip" }
client.headers  # => { "Accept-Encoding" => "gzip" }

#proxy

Accessor for the proxy server to use:

client.proxy = "http://proxy.example.com"
client.proxy  # => #<URI::HTTP:0x1026240f0 URL:http://proxy.example.com>

#auth(username, password)

Setting authentication credentials:

client.auth "username", "password"

Request methods

#get(url)

Sending an HTTP GET request:

client.get "http://example.com"

#post(url, body)

Sending an HTTP POST request:

client.post "http://example.com", "<some>xml</xml>"

HTTPI::Response

Every HTTP request method is supposed to return an HTTPI::Response containing the response code, headers and body.

response = client.get "http://example.com"

response.code     # => 200
response.headers  # => { "Content-Encoding" => "gzip" }
response.body     # => "<!DOCTYPE HTML PUBLIC ..."

Participate

I would appreciate any help to support additional libraries and methods!

TODO

Implement methods for:

  • add SSL configuration method

  • add timeout methods

Something went wrong with that request. Please try again.