HTTPI provides a common interface for different HTTP libraries.
The gem is available through Rubygems and can be installed via:
$ gem install httpi
-
httpclient ~> 2.1.5
-
curb ~> 0.7.8
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
Accessor for the HTTP request headers:
client.headers = { "Accept-Encoding" => "gzip" } client.headers # => { "Accept-Encoding" => "gzip" }
Accessor for the proxy server to use:
client.proxy = "http://proxy.example.com" client.proxy # => #<URI::HTTP:0x1026240f0 URL:http://proxy.example.com>
Setting authentication credentials:
client.auth "username", "password"
Sending an HTTP GET request:
client.get "http://example.com"
Sending an HTTP POST request:
client.post "http://example.com", "<some>xml</xml>"
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 ..."
I would appreciate any help to support additional libraries and methods!
Implement methods for:
-
add SSL configuration method
-
add timeout methods
-
add put, delete, head methods
-
Automatic redirect handling - may be too high-level for this library ?
-
Do we need our own timeout exception ? Otherwise, clients need to catch different timeout exception classes…
-
Switching adapters in one process doesn’t work