righttp

A HTTP client library written from scratch, offering an easy interface with lots of flexibility

MIT License

Downloads
28.3K
Stars
6

h1. righttp

h2. What righttp wants to achieve

righttp is intended to provide a simple and clean interface for HTTP requests while allowing to override almost every parameter of the request if it is neccessary.

It is not just a wrapper of net/http

Its philosophy is to get out of your way.

Below you can see the various ways to make a request:

h2. Interface

bc.. HTTP.get( 'http://foobar.com' )

request = HTTP.get( 'http://foobar.com?foo=bar&baz=bang') response = request.send

response = HTTP.get( 'http://foobar.com:3000?foo=bar&baz=bang').send

request = HTTP.get( 'http://foobar.com', :body => {"foo" => "bar", :baz => "bang"} ) response = request.send

request = HTTP.get( 'http://foobar.com', :body => {"foo" => "bar", :baz => "bang"} ) response = request.send

request = HTTP.get( :host => 'foobar.com', :path => "/posts", :port => 3000 :body => {"foo" => "bar", :baz => "bang"}, ) response = request.send

request = HTTP.post( 'foobar.com', :body => {"foo" => "bar"} ) response = request.send

request = HTTP.post( 'foobar.com', :body => {"foo" => "bar", :attachment => File.open("path/to/file.jpg")} ) response = request.send

request = Rig::HTTP.new( :host => "example.org", :path => "/posts", :body => { "title" => "Oh Hai", "upload" => File.open("/path/to/file.jpg") } ) response = request.send

The file will be closed once the multipart is created.

h3. Responses

When a request is send it returns a Rig::HTTPResponse which has two attributes: status, header and body

h2. Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a
    future version unintentionally.
  • Commit, do not mess with rakefile, version, or history.
    (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

h2. Copyright

Copyright (c) 2010 hukl. See LICENSE for details.