Agenda net/http 16 libraries I picked Ruby HTTP Clients Matrix API style Compatibility Supported features Performance Comparisons My Recommendations
Ruby HTTP Client libraries
HTTP client libraries I didn’t evaluate Cannot evaluate • activeresource (Rails specific) • http (under development) • http_request.rb (test doesn't pass) • nestful (no test) • typhoeus (under heavy rewrite)
Obsolete • eventmachine (built-in client is obsolete) • right_http_connection (no update) • simplehttp (no update) • rfuzz (no update)
Evaluation Axis Project Stats API style Compatibility: CRuby, JRuby, Rubinius Supported features Connection features Basic HTTP features Development support Advanced features http://bit.ly/RubyHTTPClientsFeatureTest (test/unit scripts)
sync API (1/5) - Client instance net/http, mechanize, httpclient, patron, curb, faraday client = Net::HTTP.new(host, port) p client.get(path).body
async API(1/2) - Callback em-http-request body = nil EM.run do req = EM::HttpRequest.new( 'http://www.google.com/').get req.callback do body = req.response EM.stop end req.errback do body = nil end end p body
HTML form handling of Mechanize agent = Mechanize.new page = agent.get(url)
form = page.form('login') form.email = 'firstname.lastname@example.org' form.password = 'jKH.P945wruV*qh3'
page = agent.submit(form, form.button('submit'))
Testing your client webmock by Bartosz Blimke (bblimke) Library for stubbing and setting expectations on HTTP requests in Ruby. vcr by Myron Marston (myronmarston) Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
Performance Comparisons Server Linode Xen VPS (Linode 512) at Fremont, CA Ubuntu 10.10 Apache 2.2, KeepAlive On Client AWS EC2 (m1.small) at North Virginia (us-east-1b) Ubuntu 12.04 HTTP clients w/ CRuby 1.9.3p286