# ![http.rb](https://raw.github.com/httprb/http.rb/master/logo.png) [![Gem Version](https://badge.fury.io/rb/http.svg)](https://rubygems.org/gems/http) [![Build Status](https://secure.travis-ci.org/httprb/http.svg?branch=4-x-stable)](https://travis-ci.org/httprb/http) [![Code Climate](https://codeclimate.com/github/httprb/http.svg?branch=4-x-stable)](https://codeclimate.com/github/httprb/http) [![Coverage Status](https://coveralls.io/repos/httprb/http/badge.svg?branch=4-x-stable)](https://coveralls.io/r/httprb/http) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/httprb/http/blob/master/LICENSE.txt) [Documentation] _NOTE: This is the 4.x **stable** branch. For the 3.x **stable** branch, please see:_ https://github.com/httprb/http/tree/3-x-stable ## About HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making requests from Ruby. It uses a simple method chaining system for building requests, similar to Python's [Requests]. Under the hood, http.rb uses [http_parser.rb], a fast HTTP parsing native extension based on the Node.js parser and a Java port thereof. This library isn't just yet another wrapper around Net::HTTP. It implements the HTTP protocol natively and outsources the parsing to native extensions. [requests]: http://docs.python-requests.org/en/latest/ [http_parser.rb]: https://github.com/tmm1/http_parser.rb ## Another Ruby HTTP library? Why should I care? There are a lot of HTTP libraries to choose from in the Ruby ecosystem. So why would you choose this one? Top three reasons: 1. **Clean API**: http.rb offers an easy-to-use API that should be a breath of fresh air after using something like Net::HTTP. 2. **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting features like persistent connections and fine-grained timeouts. 3. **Performance**: using native parsers and a clean, lightweight implementation, http.rb achieves the best performance of any Ruby HTTP library which implements the HTTP protocol in Ruby instead of C: | HTTP client | Time | Implementation | |--------------------------|--------|-----------------------| | curb (persistent) | 2.519 | libcurl wrapper | | em-http-request | 2.731 | EM + http_parser.rb | | Typhoeus | 2.851 | libcurl wrapper | | StreamlyFFI (persistent) | 2.853 | libcurl wrapper | | http.rb (persistent) | 2.970 | Ruby + http_parser.rb | | http.rb | 3.588 | Ruby + http_parser.rb | | HTTParty | 3.931 | Net::HTTP wrapper | | Net::HTTP | 3.959 | Pure Ruby | | Net::HTTP (persistent) | 4.043 | Pure Ruby | | open-uri | 4.479 | Net::HTTP wrapper | | Excon (persistent) | 4.618 | Pure Ruby | | Excon | 4.701 | Pure Ruby | | RestClient | 26.838 | Net::HTTP wrapper | Benchmarks performed using excon's benchmarking tool DISCLAIMER: Most benchmarks you find in READMEs are crap, including this one. These are out-of-date. If you care about performance, benchmark for yourself for your own use cases! ## Help and Discussion If you need help or just want to talk about the http.rb, visit the http.rb Google Group: https://groups.google.com/forum/#!forum/httprb You can join by email by sending a message to: [httprb+subscribe@googlegroups.com](mailto:httprb+subscribe@googlegroups.com) If you believe you've found a bug, please report it at: https://github.com/httprb/http/issues ## Installation Add this line to your application's Gemfile: ```ruby gem "http" ``` And then execute: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install http ``` Inside of your Ruby program do: ```ruby require "http" ``` ...to pull it in as a dependency. ## Documentation [Please see the http.rb wiki][documentation] for more detailed documentation and usage notes. The following API documentation is also available: * [YARD API documentation](http://www.rubydoc.info/gems/http/frames) * [Chainable module (all chainable methods)](http://www.rubydoc.info/gems/http/HTTP/Chainable) [documentation]: https://github.com/httprb/http/wiki ### Basic Usage Here's some simple examples to get you started: ```ruby >> HTTP.get("https://github.com").to_s => "\n\n\n\n\n
> HTTP.get("https://github.com") => #