Skip to content

em-http-requestvsnestful

MIT 14 4 1,220
253.3 thousand (month) Oct 25 2009 1.1.7(3 years ago)
507 3 11 NA
Apr 20 2010 41.3 thousand (month) 1.1.4(4 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

Nestful is a Ruby library for making HTTP requests. It is designed to provide a simple, easy-to-use interface for making requests and handling responses. Nestful is often used for making requests to RESTful APIs.

One of the main features of Nestful is its ability to automatically parse JSON and XML responses and return them as Ruby objects. This allows developers to easily access the data returned by an API without having to manually parse the response.

Netful is aimed at interacting with rest APIs and provides a convenient interface (see example below)

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 'nestful'

# GET request
response = Nestful.get('http://httpbin.org/get')
puts response.body
puts response.code
puts response.headers

# POST request
response = Nestful.post(
    'http://httpbin.org/post', 
    :format => :json, :payload => { :title => 'foo', :body => 'bar', :userId => 1 }
)
puts response.body

# establish interface to a specific API
class Charge < Nestful::Resource
  endpoint 'https://api.stripe.com/v1/charges'
  options :auth_type => :bearer, :password => 'sk_bar'

  def self.all
    self.new(get)
  end

  def self.find(id)
    self.new(get(id))
  end

  def refund
    post(:refund)
  end
end

Charge.all #=> []
Charge.find('ch_bar').amount

Alternatives / Similar


Was this page helpful?