Skip to content

faradayvshttp-2

MIT 39 7 5,702
4.6 million (month) Dec 19 2009 2.9.2(27 days ago)
887 6 - MIT
Sep 25 2013 131.6 thousand (month) 1.0.0(17 days ago)

Faraday is a Ruby gem that provides a simple and flexible interface for making HTTP requests. It allows you to create a Faraday connection object, which you can use to send requests and receive responses.

Faraday abstracts away the details of the underlying HTTP client library, so you can use it with different libraries such as Net::HTTP, HTTPClient, typhoeus and others.

Since Faraday can adapt many other HTTP clients it's very popular choice in web scraping.

Pure Ruby, framework and transport agnostic, implementation of HTTP/2 protocol and HPACK header compression with support for:

  • Binary framing parsing and encoding
  • Stream multiplexing and prioritization
  • Connection and stream flow control
  • Header compression and server push
  • Connection and stream management
  • And more... see API docs

Protocol specifications:

  • Hypertext Transfer Protocol Version 2 (RFC 7540)
  • HPACK: Header Compression for HTTP/2 (RFC 7541)

Highlights


http2

Example Use


# GET requests
response = Faraday.get('http://httpbingo.org')
put response.status
put response.headers
put response.body

# or use a persistent client session:
conn = Faraday.new(
  url: 'http://httpbin.org/get',
  params: {param: '1'},
  headers: {'Content-Type' => 'application/json'}
)

# POST requests
response = conn.post('/post') do |req|
  req.params['limit'] = 100
  req.body = {query: 'chunky bacon'}.to_json
end
require 'http/2'

# GET request
client = HTTP2::Client.new
response = client.get("https://httpbin.org/get")
puts response.body

# POST reuqest
data = { name: "value" }
response = client.post("https://www.example.com", data)

Alternatives / Similar


Was this page helpful?