Skip to content

em-http-requestvshttpclient

MIT 14 4 1,220
253.3 thousand (month) Oct 25 2009 1.1.7(3 years ago)
699 4 94 ruby
Jul 25 2009 3.8 million (month) 2.8.3(7 years ago)

em-http-request is a Ruby gem for making asynchronous HTTP requests using EventMachine. It allows you to perform multiple requests simultaneously and handle the responses as they come in, rather than waiting for each request to complete before making the next one.

In short it supports: - Asynchronous HTTP API for single & parallel request execution - Keep-Alive and HTTP pipelining support - Auto-follow 3xx redirects with max depth - Automatic gzip & deflate decoding - Streaming response processing - Streaming file uploads - HTTP proxy and SOCKS5 support - Basic Auth & OAuth - Connection-level & global middleware support - HTTP parser via http_parser.rb - Works wherever EventMachine runs: Rubinius, JRuby, MRI

HTTPClient is a Ruby gem that provides a simple and flexible interface for making HTTP requests. It's a full-featured HTTP client library with support for cookies, redirects, proxy, and more. It's built on top of the libwww-perl library, which is a widely-used, robust and well-documented library.

Features:

  • methods like GET/HEAD/POST/* via HTTP/1.1.
  • HTTPS(SSL), Cookies, proxy, authentication(Digest, NTLM, Basic), etc.
  • asynchronous HTTP request, streaming HTTP request.
  • debug mode CLI.
  • by contrast with net/http in standard distribution;
  • Cookies support
  • MT-safe
  • streaming POST (POST with File/IO)
  • Digest auth
  • Negotiate/NTLM auth for WWW-Authenticate (requires net/ntlm module; rubyntlm gem)
  • NTLM auth for Proxy-Authenticate (requires 'win32/sspi' module; rubysspi gem)
  • extensible with filter interface
  • you don't have to care HTTP/1.1 persistent connection (httpclient cares instead of you)

Example Use


EventMachine.run {
  http = EventMachine::HttpRequest.new('http://google.com/').get :query => {'keyname' => 'value'}

  # add callback for errors:
  http.errback { p 'Uh oh'; EM.stop }

  # add callback for successful requests
  http.callback {
    p http.response_header.status
    p http.response_header
    p http.response

    EventMachine.stop
  }
}
require 'httpclient'

client = HTTPClient.new
# GET requests
response = client.get("http://httpbin.org/get")
puts response.content

# POST requests
data = { name: "value" }
response = client.post("http://httpbin.org/post", data)
puts response.content

Alternatives / Similar


Was this page helpful?