SlideShare a Scribd company logo
Ruby HTTP clients comparison
            Hiroshi Nakamura
          nahi at Twitter, github

    Technical Architect at Appirio Japan
       CRuby and JRuby committer
   Asakusa.rb: http://qwik.jp/asakusarb/
Ruby HTTP Clients Matrix
advantages-and-disadvantages comparison of
HTTP client libraries




      http://bit.ly/RubyHTTPClients2012
            Disclaimer: I'm the author of "httpclient"
Agenda
net/http
16 libraries I picked
Ruby HTTP Clients Matrix
  API style
  Compatibility
  Supported features
Performance Comparisons
My Recommendations
net/http




           Net::HTTP::Proxy?
           net/https?
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)
Project Stats
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Project Stats
API style
Ruby HTTP clients comparison
sync API (1/5) - Client instance
net/http, mechanize, httpclient, patron, curb, faraday
        client = Net::HTTP.new(host, port)
        p client.get(path).body

        client = Mechanize.new
        client = HTTPClient.new
        client = Patron::Session.new
        p client.get(url).body

        curl = Curl::Easy.new(url)
        curl.http_get
        p curl.body_str

        client = Faraday.new(:url => baseurl)
        p client.get(path).body
sync API (2/5) - Client class
      restfulie, excon, httpi

    p Restfulie.at(url).get!.body
    p Excon.get(url).body
    p HTTPI.get(url).body
sync API (3/5) - Resource
                   rest-client, rufus-verbs

rs = RestClient::Resource.new('http://example.com')
rs['posts/1/comments'].post 'Good article.', :content_type => 'text/plain'

ep = EndPoint.new(
 :host => "resta.farian.host", :port => 80, :resource => "inventory/tools")
res = ep.get :id => 1
res = ep.get :id => 2
sync API (4/5) - Include & Customize
                   httparty, weary

   client = Class.new { include HTTParty }
   p client.get(url)

   class WearyClient < Weary::Client
     domain 'http://api.target.org/'
     get :retrieve, '{path}'
   end
   p WearyClient.new.fetch(:path => path).perform.body
sync API (5/5) - Others
           open-uri.rb, wrest
# open-uri.rb
p open(url) { |f| f.read }

# wrest
p 'http://www.google.co.jp/'.to_uri.get.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
async API(2/2) - Polling
   httpclient, weary, wrest

  client = HTTPClient.new
  conn = client.get_async(url)
  conn.finished? # => false

  # ...
  io = conn.pop.content
  while str = io.read(4096)
    p str
  end
parallel API - curb
responses = []
m = Curl::Multi.new
urls.each do |url|
  responses[url] = ''
  m.add(Curl::Easy.new(url) { |curl|
    curl.on_body { |data|
      responses[url] << data
      data.bytesize
    }
  })
end
m.perform
p responses.map { |e| e.bytesize }
Ruby HTTP clients comparison
Ruby HTTP clients comparison
API style
Compatibility
Ruby HTTP clients comparison
Compatibility
Connection features
Ruby HTTP clients comparison
3 types of HTTP connections
Ruby HTTP clients comparison
Keep-Alive in em-http-request
 body = []
 EM.run do
   conn = EventMachine::HttpRequest.new(server.url)
   req1 = conn.get(:keepalive => true)
   req1.callback {
     body << req1.response
     req2 = conn.get(:keepalive => true)
     req2.callback {
       body << req2.response
       req3 = conn.get(:keepalive => true)
       req3.callback {
         body << req3.response
         req4 = conn.get(:keepalive => true)
         req4.callback {
           body << req4.response
           EM.stop
         req4.errback { ... }}
       req3.errback { ... }}
     req2.errback { ... }}
   req1.errback { ... }
 end
Pipelining in em-http-request
 body =   []
 EM.run   do
   conn   = EventMachine::HttpRequest.new(server.url)
   req1   = conn.get(:keepalive => true)
   req2   = conn.get(:keepalive => true)
   req3   = conn.get(:keepalive => true)
   req4   = conn.get()

  req1.callback   {    body     <<   req1.response }
  req2.callback   {    body     <<   req2.response }
  req3.callback   {    body     <<   req3.response }
  req4.callback   {    body     <<   req4.response; EM.stop }

   req1.errback   {   ...   }
   req2.errback   {   ...   }
   req3.errback   {   ...   }
   req4.errback   {   ...   }
 end
Ruby HTTP clients comparison
NO verification by default?!

if http.use_ssl?
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  if options[:ssl_ca_file]
    http.ca_file = options[:ssl_ca_file]
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  end
end




options[:ssl_ca_file] == nil => VERIFY_NONE
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Connection features
Basic HTTP features
Ruby HTTP clients comparison
Ruby HTTP clients comparison
IRI: Internationalized Resource
                Identifier

client.get("http://www.ebooks.com/797059/some-kind-
of-peace/grebe-camilla-träff-åsa-norlen-paul/")



            uri.rb doesn't support IRI
              addressable/uri does
Ruby HTTP clients comparison
"Cross-site Cooking" bug in httpclient

Set-Cookie: TEST=test; path=/; domain=.com

          httpclient eats this cookie and
             send it to all *.com site

    Mechanize handles it properly like browsers

  http://en.wikipedia.org/wiki/Cross-site_cooking
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Streaming upload/download
# Chunked upload with Patron
client = Patron::Session.new
res = client.request(:post, url, {}, :file => path_to_upload)
# Chunked download
client.get_file(url, path_to_write)

# Chunked upload with em-http-request
req = EM::HttpRequest.new(url).post :file => path_to_upload
# Chunked download
req = EM::HttpRequest.new(url).get
req.stream do |chunk|
  p chunk
end
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Basic HTTP features
Development Support
Ruby HTTP clients comparison
Response stubbing
# Stubbing response body
client = HTTPClient.new
client.test_loopback_response << 'Hello!'
client.get('http://www.example.com/hello').body
#=> "Hello!"

# Stubbing HTTP response
client.test_loopback_http_response <<
  "HTTP/1.0 302 Found¥r¥nLocation: http://foo/¥r¥n¥r¥n" <<
  "HTTP/1.0 200 OK¥r¥n¥r¥nHello!"
client.post('http://www.example.com/todo',
  :follow_redirect => true, :body => '{}').body
#=> "Hello!"
Ruby HTTP clients comparison
Ruby HTTP clients comparison
IRB like shell
      rest-client, httpclient, wrest

% restclient https://example.com user pass
>> delete '/private/resource'

% httpclient
>> get "https://www.google.com", :q => :ruby

% wrest
>> 'http://www.google.com?q=ruby'.to_uri.get
Replayable log
                        rest-client

% RESTCLIENT_LOG=/tmp/restclient.log restclient
>> RestClient.get "https://www.google.com/"
...

% cat /tmp/restclient.log
RestClient.get "https://www.google.com/", "Accept"=>"*/*;
q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate"
# => 200 OK | text/html 13354 bytes
Ruby HTTP clients comparison
Development Support
Advanced features
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
Ruby HTTP clients comparison
HTML form handling of Mechanize

 agent = Mechanize.new
 page = agent.get(url)

 form = page.form('login')
 form.email = 'nahi@ruby-lang.org'
 form.password = 'jKH.P945wruV*qh3'

 page = agent.submit(form, form.button('submit'))
Advanced features
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

Multiple downloads of 177B.html and 24MB.zip

Don't take it serious!
   http://bit.ly/RubyHTTPClientsBenchmarkScript
Multiple 177B downloads




                          [sec]
[sec]
[sec]
My Recommendations
• Speed is the king => em-http-request, curb w/
  multi
• HTML operation, Cookies => Mechanize
• API client => Faraday and adapter based impls
• SSL, Connectivity => httpclient

Check the matrix before you use the libraries
Please let me know when you find incorrect cell
Development Timeline
Ad

More Related Content

What's hot (20)

C#の強み、或いは何故PHPから乗り換えるのか
C#の強み、或いは何故PHPから乗り換えるのかC#の強み、或いは何故PHPから乗り換えるのか
C#の強み、或いは何故PHPから乗り換えるのか
Yoshifumi Kawai
 
Amazon Kinesis Video Streams WebRTC 使ってみた
Amazon Kinesis Video Streams WebRTC 使ってみたAmazon Kinesis Video Streams WebRTC 使ってみた
Amazon Kinesis Video Streams WebRTC 使ってみた
mganeko
 
私にとってのテスト
私にとってのテスト私にとってのテスト
私にとってのテスト
Takuto Wada
 
こわくない Git
こわくない Gitこわくない Git
こわくない Git
Kota Saito
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
Hiroshi Tokumaru
 
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
日本マイクロソフト株式会社
 
DevOpsにおけるAnsibleの立ち位置と使い所
DevOpsにおけるAnsibleの立ち位置と使い所DevOpsにおけるAnsibleの立ち位置と使い所
DevOpsにおけるAnsibleの立ち位置と使い所
Hidetoshi Hirokawa
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Dockerイメージの理解とコンテナのライフサイクル
Dockerイメージの理解とコンテナのライフサイクルDockerイメージの理解とコンテナのライフサイクル
Dockerイメージの理解とコンテナのライフサイクル
Masahito Zembutsu
 
RETEアルゴリズムを使いこなせ
RETEアルゴリズムを使いこなせRETEアルゴリズムを使いこなせ
RETEアルゴリズムを使いこなせ
Masahiko Umeno
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwright
twMVC
 
ジェネリクスの基礎と クラス設計への応用
ジェネリクスの基礎とクラス設計への応用ジェネリクスの基礎とクラス設計への応用
ジェネリクスの基礎と クラス設計への応用
nagise
 
脱RESTful API設計の提案
脱RESTful API設計の提案脱RESTful API設計の提案
脱RESTful API設計の提案
樽八 仲川
 
91APP: 從 "零" 開始的 DevOps
91APP: 從 "零" 開始的 DevOps91APP: 從 "零" 開始的 DevOps
91APP: 從 "零" 開始的 DevOps
Andrew Wu
 
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
NTT DATA Technology & Innovation
 
最強オブジェクト指向言語 JavaScript 再入門!
最強オブジェクト指向言語 JavaScript 再入門!最強オブジェクト指向言語 JavaScript 再入門!
最強オブジェクト指向言語 JavaScript 再入門!
Yuji Nojima
 
Spring Boot on Kubernetes : Yahoo!ズバトク事例 #jjug_ccc
Spring Boot on Kubernetes : Yahoo!ズバトク事例 #jjug_cccSpring Boot on Kubernetes : Yahoo!ズバトク事例 #jjug_ccc
Spring Boot on Kubernetes : Yahoo!ズバトク事例 #jjug_ccc
Yahoo!デベロッパーネットワーク
 
RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話
Takuto Wada
 
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
div Inc
 
Graph Database and Amazon Neptune
Graph Database and Amazon NeptuneGraph Database and Amazon Neptune
Graph Database and Amazon Neptune
Amazon Web Services Japan
 
C#の強み、或いは何故PHPから乗り換えるのか
C#の強み、或いは何故PHPから乗り換えるのかC#の強み、或いは何故PHPから乗り換えるのか
C#の強み、或いは何故PHPから乗り換えるのか
Yoshifumi Kawai
 
Amazon Kinesis Video Streams WebRTC 使ってみた
Amazon Kinesis Video Streams WebRTC 使ってみたAmazon Kinesis Video Streams WebRTC 使ってみた
Amazon Kinesis Video Streams WebRTC 使ってみた
mganeko
 
私にとってのテスト
私にとってのテスト私にとってのテスト
私にとってのテスト
Takuto Wada
 
こわくない Git
こわくない Gitこわくない Git
こわくない Git
Kota Saito
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
Hiroshi Tokumaru
 
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
【BS13】チーム開発がこんなにも快適に!コーディングもデバッグも GitHub 上で。 GitHub Codespaces で叶えられるシームレスな開発
日本マイクロソフト株式会社
 
DevOpsにおけるAnsibleの立ち位置と使い所
DevOpsにおけるAnsibleの立ち位置と使い所DevOpsにおけるAnsibleの立ち位置と使い所
DevOpsにおけるAnsibleの立ち位置と使い所
Hidetoshi Hirokawa
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Dockerイメージの理解とコンテナのライフサイクル
Dockerイメージの理解とコンテナのライフサイクルDockerイメージの理解とコンテナのライフサイクル
Dockerイメージの理解とコンテナのライフサイクル
Masahito Zembutsu
 
RETEアルゴリズムを使いこなせ
RETEアルゴリズムを使いこなせRETEアルゴリズムを使いこなせ
RETEアルゴリズムを使いこなせ
Masahiko Umeno
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwright
twMVC
 
ジェネリクスの基礎と クラス設計への応用
ジェネリクスの基礎とクラス設計への応用ジェネリクスの基礎とクラス設計への応用
ジェネリクスの基礎と クラス設計への応用
nagise
 
脱RESTful API設計の提案
脱RESTful API設計の提案脱RESTful API設計の提案
脱RESTful API設計の提案
樽八 仲川
 
91APP: 從 "零" 開始的 DevOps
91APP: 從 "零" 開始的 DevOps91APP: 從 "零" 開始的 DevOps
91APP: 從 "零" 開始的 DevOps
Andrew Wu
 
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
1日5分でPostgreSQLに詳しくなるアプリの開発 ~PostgRESTを使ってみた~(第38回PostgreSQLアンカンファレンス@オンライン 発...
NTT DATA Technology & Innovation
 
最強オブジェクト指向言語 JavaScript 再入門!
最強オブジェクト指向言語 JavaScript 再入門!最強オブジェクト指向言語 JavaScript 再入門!
最強オブジェクト指向言語 JavaScript 再入門!
Yuji Nojima
 
RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話
Takuto Wada
 
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
非エンジニアのためのこれだけは押さえておきたいWEBサービスの基礎技術
div Inc
 

Viewers also liked (20)

JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
Wynn Netherland
 
Ruby HTTP clients
Ruby HTTP clientsRuby HTTP clients
Ruby HTTP clients
Zoran Majstorovic
 
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
Hiroh Satoh
 
Human toxicity, environmental impact and legal implications of water fluorida...
Human toxicity, environmental impact and legal implications of water fluorida...Human toxicity, environmental impact and legal implications of water fluorida...
Human toxicity, environmental impact and legal implications of water fluorida...
Declan Waugh
 
These words I share, written from despair, read them, speak them, but do so w...
These words I share, written from despair, read them, speak them, but do so w...These words I share, written from despair, read them, speak them, but do so w...
These words I share, written from despair, read them, speak them, but do so w...
Blair Stuart
 
Isu isu trenda terkini dalam teknologi pendidikan
Isu isu trenda terkini dalam teknologi pendidikanIsu isu trenda terkini dalam teknologi pendidikan
Isu isu trenda terkini dalam teknologi pendidikan
Renee Evelyn
 
C# & AWS Lambda
C# & AWS LambdaC# & AWS Lambda
C# & AWS Lambda
Pat Hermens
 
Hazop gijutsushikai chubu koukuukai
Hazop gijutsushikai chubu koukuukai Hazop gijutsushikai chubu koukuukai
Hazop gijutsushikai chubu koukuukai
Kiyoshi Ogawa
 
Yapc Asia 2009 ペパボでのPerlの使い方
Yapc Asia 2009 ペパボでのPerlの使い方Yapc Asia 2009 ペパボでのPerlの使い方
Yapc Asia 2009 ペパボでのPerlの使い方
hiboma
 
The New Framework for Information Literacy for Higher Education
The New Framework for Information Literacy for Higher EducationThe New Framework for Information Literacy for Higher Education
The New Framework for Information Literacy for Higher Education
Trudi Jacobson
 
GBM Group Based Marketing: Marketing to Groups
GBM Group Based Marketing: Marketing to GroupsGBM Group Based Marketing: Marketing to Groups
GBM Group Based Marketing: Marketing to Groups
Scott Levine
 
How to Kill a Word
How to Kill a WordHow to Kill a Word
How to Kill a Word
Patrick McLean
 
好みや多数決で決めない、デザインとの正しい付き合い方
好みや多数決で決めない、デザインとの正しい付き合い方好みや多数決で決めない、デザインとの正しい付き合い方
好みや多数決で決めない、デザインとの正しい付き合い方
Yasuhisa Hasegawa
 
Corso storytelling a Gemona
Corso storytelling a GemonaCorso storytelling a Gemona
Corso storytelling a Gemona
Gemona Turismo
 
Ui qa tools
Ui qa toolsUi qa tools
Ui qa tools
Sevilla QA
 
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Ítalo de Oliveira Mendonça
 
Escaneado 09 03-2017 10.02
Escaneado 09 03-2017 10.02Escaneado 09 03-2017 10.02
Escaneado 09 03-2017 10.02
Juan Carreón
 
ブレンダーをDisってみる
ブレンダーをDisってみるブレンダーをDisってみる
ブレンダーをDisってみる
Tetsuo Mitsuda
 
4 questions to help you secure ePHI today
4 questions to help you secure ePHI today4 questions to help you secure ePHI today
4 questions to help you secure ePHI today
Sarabeth Marcello
 
Trend & Challenge Digital Marketing di Indonesia 2017
Trend & Challenge Digital Marketing di Indonesia 2017 Trend & Challenge Digital Marketing di Indonesia 2017
Trend & Challenge Digital Marketing di Indonesia 2017
Nicko Krisna
 
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
ぼくのかんがえたさいきょうのうぇぶあぷりけーしょんふれーむわーく - YAPC Asia 2011
Hiroh Satoh
 
Human toxicity, environmental impact and legal implications of water fluorida...
Human toxicity, environmental impact and legal implications of water fluorida...Human toxicity, environmental impact and legal implications of water fluorida...
Human toxicity, environmental impact and legal implications of water fluorida...
Declan Waugh
 
These words I share, written from despair, read them, speak them, but do so w...
These words I share, written from despair, read them, speak them, but do so w...These words I share, written from despair, read them, speak them, but do so w...
These words I share, written from despair, read them, speak them, but do so w...
Blair Stuart
 
Isu isu trenda terkini dalam teknologi pendidikan
Isu isu trenda terkini dalam teknologi pendidikanIsu isu trenda terkini dalam teknologi pendidikan
Isu isu trenda terkini dalam teknologi pendidikan
Renee Evelyn
 
Hazop gijutsushikai chubu koukuukai
Hazop gijutsushikai chubu koukuukai Hazop gijutsushikai chubu koukuukai
Hazop gijutsushikai chubu koukuukai
Kiyoshi Ogawa
 
Yapc Asia 2009 ペパボでのPerlの使い方
Yapc Asia 2009 ペパボでのPerlの使い方Yapc Asia 2009 ペパボでのPerlの使い方
Yapc Asia 2009 ペパボでのPerlの使い方
hiboma
 
The New Framework for Information Literacy for Higher Education
The New Framework for Information Literacy for Higher EducationThe New Framework for Information Literacy for Higher Education
The New Framework for Information Literacy for Higher Education
Trudi Jacobson
 
GBM Group Based Marketing: Marketing to Groups
GBM Group Based Marketing: Marketing to GroupsGBM Group Based Marketing: Marketing to Groups
GBM Group Based Marketing: Marketing to Groups
Scott Levine
 
好みや多数決で決めない、デザインとの正しい付き合い方
好みや多数決で決めない、デザインとの正しい付き合い方好みや多数決で決めない、デザインとの正しい付き合い方
好みや多数決で決めない、デザインとの正しい付き合い方
Yasuhisa Hasegawa
 
Corso storytelling a Gemona
Corso storytelling a GemonaCorso storytelling a Gemona
Corso storytelling a Gemona
Gemona Turismo
 
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Bundesliga Report - 10 years of academies - Talent pools of top-level German ...
Ítalo de Oliveira Mendonça
 
Escaneado 09 03-2017 10.02
Escaneado 09 03-2017 10.02Escaneado 09 03-2017 10.02
Escaneado 09 03-2017 10.02
Juan Carreón
 
ブレンダーをDisってみる
ブレンダーをDisってみるブレンダーをDisってみる
ブレンダーをDisってみる
Tetsuo Mitsuda
 
4 questions to help you secure ePHI today
4 questions to help you secure ePHI today4 questions to help you secure ePHI today
4 questions to help you secure ePHI today
Sarabeth Marcello
 
Trend & Challenge Digital Marketing di Indonesia 2017
Trend & Challenge Digital Marketing di Indonesia 2017 Trend & Challenge Digital Marketing di Indonesia 2017
Trend & Challenge Digital Marketing di Indonesia 2017
Nicko Krisna
 
Ad

Similar to Ruby HTTP clients comparison (20)

Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
Rpi python web
Rpi python webRpi python web
Rpi python web
sewoo lee
 
Server Side Swift: Vapor
Server Side Swift: VaporServer Side Swift: Vapor
Server Side Swift: Vapor
Paweł Kowalczuk
 
Java web programming
Java web programmingJava web programming
Java web programming
Ching Yi Chan
 
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Timur Shemsedinov
 
Web Server.pdf
Web Server.pdfWeb Server.pdf
Web Server.pdf
Bareen Shaikh
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Rest with Spring
Rest with SpringRest with Spring
Rest with Spring
Eugen Paraschiv
 
SERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servletsSERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
Palestra VCR
Palestra VCRPalestra VCR
Palestra VCR
Cássio Marques
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
nickmbailey
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
ciklum_ods
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
Shubhani Jain
 
Scaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby undergroundScaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby underground
Omer Gazit
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Rack
RackRack
Rack
Sarah Allen
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
Kerry Buckley
 
Rpi python web
Rpi python webRpi python web
Rpi python web
sewoo lee
 
Java web programming
Java web programmingJava web programming
Java web programming
Ching Yi Chan
 
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...Rapid API development examples for Impress Application Server / Node.js (jsfw...
Rapid API development examples for Impress Application Server / Node.js (jsfw...
Timur Shemsedinov
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
SERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servletsSERVLETS (2).pptxintroduction to servlet with all servlets
SERVLETS (2).pptxintroduction to servlet with all servlets
RadhikaP41
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Masahiro Nagano
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
Clojure and the Web
Clojure and the WebClojure and the Web
Clojure and the Web
nickmbailey
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
ciklum_ods
 
Scaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby undergroundScaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby underground
Omer Gazit
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Testing http calls with Webmock and VCR
Testing http calls with Webmock and VCRTesting http calls with Webmock and VCR
Testing http calls with Webmock and VCR
Kerry Buckley
 
Ad

More from Hiroshi Nakamura (10)

エンタープライズソフトウェア開発とOSS
エンタープライズソフトウェア開発とOSSエンタープライズソフトウェア開発とOSS
エンタープライズソフトウェア開発とOSS
Hiroshi Nakamura
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in ruby
Hiroshi Nakamura
 
Embulk 20150411
Embulk 20150411Embulk 20150411
Embulk 20150411
Hiroshi Nakamura
 
ちゃんと理解するForce.com canvas
ちゃんと理解するForce.com canvasちゃんと理解するForce.com canvas
ちゃんと理解するForce.com canvas
Hiroshi Nakamura
 
Java SE 7 InvokeDynamic in JRuby
Java SE 7 InvokeDynamic in JRubyJava SE 7 InvokeDynamic in JRuby
Java SE 7 InvokeDynamic in JRuby
Hiroshi Nakamura
 
JavaOne Tokyo JVM言語BOF ベンチマーク JRuby
JavaOne Tokyo JVM言語BOF ベンチマーク JRubyJavaOne Tokyo JVM言語BOF ベンチマーク JRuby
JavaOne Tokyo JVM言語BOF ベンチマーク JRuby
Hiroshi Nakamura
 
現実世界のJRuby(ショートバージョン)
現実世界のJRuby(ショートバージョン)現実世界のJRuby(ショートバージョン)
現実世界のJRuby(ショートバージョン)
Hiroshi Nakamura
 
現実世界のJRuby
現実世界のJRuby現実世界のJRuby
現実世界のJRuby
Hiroshi Nakamura
 
HSM用ミドルウェア Conduit Toolkitの概要と使い方
HSM用ミドルウェア Conduit Toolkitの概要と使い方HSM用ミドルウェア Conduit Toolkitの概要と使い方
HSM用ミドルウェア Conduit Toolkitの概要と使い方
Hiroshi Nakamura
 
HSM超入門講座
HSM超入門講座HSM超入門講座
HSM超入門講座
Hiroshi Nakamura
 
エンタープライズソフトウェア開発とOSS
エンタープライズソフトウェア開発とOSSエンタープライズソフトウェア開発とOSS
エンタープライズソフトウェア開発とOSS
Hiroshi Nakamura
 
Information security programming in ruby
Information security programming in rubyInformation security programming in ruby
Information security programming in ruby
Hiroshi Nakamura
 
ちゃんと理解するForce.com canvas
ちゃんと理解するForce.com canvasちゃんと理解するForce.com canvas
ちゃんと理解するForce.com canvas
Hiroshi Nakamura
 
Java SE 7 InvokeDynamic in JRuby
Java SE 7 InvokeDynamic in JRubyJava SE 7 InvokeDynamic in JRuby
Java SE 7 InvokeDynamic in JRuby
Hiroshi Nakamura
 
JavaOne Tokyo JVM言語BOF ベンチマーク JRuby
JavaOne Tokyo JVM言語BOF ベンチマーク JRubyJavaOne Tokyo JVM言語BOF ベンチマーク JRuby
JavaOne Tokyo JVM言語BOF ベンチマーク JRuby
Hiroshi Nakamura
 
現実世界のJRuby(ショートバージョン)
現実世界のJRuby(ショートバージョン)現実世界のJRuby(ショートバージョン)
現実世界のJRuby(ショートバージョン)
Hiroshi Nakamura
 
HSM用ミドルウェア Conduit Toolkitの概要と使い方
HSM用ミドルウェア Conduit Toolkitの概要と使い方HSM用ミドルウェア Conduit Toolkitの概要と使い方
HSM用ミドルウェア Conduit Toolkitの概要と使い方
Hiroshi Nakamura
 

Ruby HTTP clients comparison

  • 1. Ruby HTTP clients comparison Hiroshi Nakamura nahi at Twitter, github Technical Architect at Appirio Japan CRuby and JRuby committer Asakusa.rb: http://qwik.jp/asakusarb/
  • 2. Ruby HTTP Clients Matrix advantages-and-disadvantages comparison of HTTP client libraries http://bit.ly/RubyHTTPClients2012 Disclaimer: I'm the author of "httpclient"
  • 3. Agenda net/http 16 libraries I picked Ruby HTTP Clients Matrix API style Compatibility Supported features Performance Comparisons My Recommendations
  • 4. net/http Net::HTTP::Proxy? net/https?
  • 5. Ruby HTTP Client libraries
  • 6. 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)
  • 7. 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)
  • 15. sync API (1/5) - Client instance net/http, mechanize, httpclient, patron, curb, faraday client = Net::HTTP.new(host, port) p client.get(path).body client = Mechanize.new client = HTTPClient.new client = Patron::Session.new p client.get(url).body curl = Curl::Easy.new(url) curl.http_get p curl.body_str client = Faraday.new(:url => baseurl) p client.get(path).body
  • 16. sync API (2/5) - Client class restfulie, excon, httpi p Restfulie.at(url).get!.body p Excon.get(url).body p HTTPI.get(url).body
  • 17. sync API (3/5) - Resource rest-client, rufus-verbs rs = RestClient::Resource.new('http://example.com') rs['posts/1/comments'].post 'Good article.', :content_type => 'text/plain' ep = EndPoint.new( :host => "resta.farian.host", :port => 80, :resource => "inventory/tools") res = ep.get :id => 1 res = ep.get :id => 2
  • 18. sync API (4/5) - Include & Customize httparty, weary client = Class.new { include HTTParty } p client.get(url) class WearyClient < Weary::Client domain 'http://api.target.org/' get :retrieve, '{path}' end p WearyClient.new.fetch(:path => path).perform.body
  • 19. sync API (5/5) - Others open-uri.rb, wrest # open-uri.rb p open(url) { |f| f.read } # wrest p 'http://www.google.co.jp/'.to_uri.get.body
  • 20. 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
  • 21. async API(2/2) - Polling httpclient, weary, wrest client = HTTPClient.new conn = client.get_async(url) conn.finished? # => false # ... io = conn.pop.content while str = io.read(4096) p str end
  • 22. parallel API - curb responses = [] m = Curl::Multi.new urls.each do |url| responses[url] = '' m.add(Curl::Easy.new(url) { |curl| curl.on_body { |data| responses[url] << data data.bytesize } }) end m.perform p responses.map { |e| e.bytesize }
  • 31. 3 types of HTTP connections
  • 33. Keep-Alive in em-http-request body = [] EM.run do conn = EventMachine::HttpRequest.new(server.url) req1 = conn.get(:keepalive => true) req1.callback { body << req1.response req2 = conn.get(:keepalive => true) req2.callback { body << req2.response req3 = conn.get(:keepalive => true) req3.callback { body << req3.response req4 = conn.get(:keepalive => true) req4.callback { body << req4.response EM.stop req4.errback { ... }} req3.errback { ... }} req2.errback { ... }} req1.errback { ... } end
  • 34. Pipelining in em-http-request body = [] EM.run do conn = EventMachine::HttpRequest.new(server.url) req1 = conn.get(:keepalive => true) req2 = conn.get(:keepalive => true) req3 = conn.get(:keepalive => true) req4 = conn.get() req1.callback { body << req1.response } req2.callback { body << req2.response } req3.callback { body << req3.response } req4.callback { body << req4.response; EM.stop } req1.errback { ... } req2.errback { ... } req3.errback { ... } req4.errback { ... } end
  • 36. NO verification by default?! if http.use_ssl? http.verify_mode = OpenSSL::SSL::VERIFY_NONE if options[:ssl_ca_file] http.ca_file = options[:ssl_ca_file] http.verify_mode = OpenSSL::SSL::VERIFY_PEER end end options[:ssl_ca_file] == nil => VERIFY_NONE
  • 44. IRI: Internationalized Resource Identifier client.get("http://www.ebooks.com/797059/some-kind- of-peace/grebe-camilla-träff-åsa-norlen-paul/") uri.rb doesn't support IRI addressable/uri does
  • 46. "Cross-site Cooking" bug in httpclient Set-Cookie: TEST=test; path=/; domain=.com httpclient eats this cookie and send it to all *.com site Mechanize handles it properly like browsers http://en.wikipedia.org/wiki/Cross-site_cooking
  • 51. Streaming upload/download # Chunked upload with Patron client = Patron::Session.new res = client.request(:post, url, {}, :file => path_to_upload) # Chunked download client.get_file(url, path_to_write) # Chunked upload with em-http-request req = EM::HttpRequest.new(url).post :file => path_to_upload # Chunked download req = EM::HttpRequest.new(url).get req.stream do |chunk| p chunk end
  • 57. Response stubbing # Stubbing response body client = HTTPClient.new client.test_loopback_response << 'Hello!' client.get('http://www.example.com/hello').body #=> "Hello!" # Stubbing HTTP response client.test_loopback_http_response << "HTTP/1.0 302 Found¥r¥nLocation: http://foo/¥r¥n¥r¥n" << "HTTP/1.0 200 OK¥r¥n¥r¥nHello!" client.post('http://www.example.com/todo', :follow_redirect => true, :body => '{}').body #=> "Hello!"
  • 60. IRB like shell rest-client, httpclient, wrest % restclient https://example.com user pass >> delete '/private/resource' % httpclient >> get "https://www.google.com", :q => :ruby % wrest >> 'http://www.google.com?q=ruby'.to_uri.get
  • 61. Replayable log rest-client % RESTCLIENT_LOG=/tmp/restclient.log restclient >> RestClient.get "https://www.google.com/" ... % cat /tmp/restclient.log RestClient.get "https://www.google.com/", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate" # => 200 OK | text/html 13354 bytes
  • 69. HTML form handling of Mechanize agent = Mechanize.new page = agent.get(url) form = page.form('login') form.email = '[email protected]' form.password = 'jKH.P945wruV*qh3' page = agent.submit(form, form.button('submit'))
  • 71. 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.
  • 72. 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 Multiple downloads of 177B.html and 24MB.zip Don't take it serious! http://bit.ly/RubyHTTPClientsBenchmarkScript
  • 74. [sec]
  • 75. [sec]
  • 76. My Recommendations • Speed is the king => em-http-request, curb w/ multi • HTML operation, Cookies => Mechanize • API client => Faraday and adapter based impls • SSL, Connectivity => httpclient Check the matrix before you use the libraries Please let me know when you find incorrect cell