Skip to content
This repository has been archived by the owner on Sep 7, 2019. It is now read-only.

MGPalmer/httpi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • 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

About

Common interface for Ruby HTTP libraries

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%