Code Monkey home page Code Monkey logo

httpi's Introduction

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

httpi's People

Contributors

rubiii avatar

Watchers

Martin Tepper avatar Frank Brandewiede avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.