Awesome
Awesome Faraday
A curated list of awesome middleware and adapters for Faraday. If you want your adapter or middleware to feature in this list, please open a discussion or a PR.
Adapters
Faraday allows you to change the adapter, the element in the stack responsible for performing the HTTP request, with ease, by the combination of a standardised API to provide configuration and request details, and a powerful set of middleware. However, each adapter can also offer unique features, or lack the support for others. The following table show the available adapters and which features they support.
Adapter | Bundled with Faraday | Reason Phrase parsing | Compression (Gzip, Deflate) | Response Streaming | Parallel Requests | GET, HEAD, DELETE, TRACE Request Body | HEAD Response Body | TRACE Method | Local Socket Binding |
---|---|---|---|---|---|---|---|---|---|
Async::HTTP::Faraday | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
EM::HTTP | v1 only | ✔️ | ✖️ | ✖️ | ✔️ | ✔️ | ✖️ | ✔️ | ✔️ |
EM::Synchrony | v1 only | ✔️ | ✖️ | ✖️ | ✔️ | ✔️ | ✖️ | ✔️ | ✔️ |
Excon | v1 only | ✔️ | ✖️ | ✖️ | ✖️ | ✔️ | ✔️ | ✔️ | ✖️ |
HttpClient | v1 only | ✔️ | ✔️ | ✖️ | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ |
Net::HTTP | ✔️ | ✔️ | ✔️ | ✔️ | ✖️ | ✔️ | ✔️ | ✔️ | ✖️ |
Net::HTTP::Persistent | v1 only | ✔️ | ✔️ | ✔️ | ✖️ | ✔️ | ✔️ | ✔️ | ✖️ |
Patron | v1 only | ✔️ | ✖️ | ✖️ | ✖️ | ✖️ | ✔️ | ✖️ | ✖️ |
Typhoeus | v1 only | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✖️ |
HTTP.rb | ✖️ | ✔️ | ✖️ | ✔️ | ✖️ | ✔️ | ✖️ | ✔️ | ✔️ |
httpx | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
Middleware
Under the hood, Faraday uses a Rack-inspired middleware stack for making requests. Much of Faraday’s power is unlocked with custom middleware. Some middleware is included with Faraday, and others are in external gems. Learn more about Middleware.
In addition to this curated list of middleware, we would like to specifically call your attention to middleware that is helpful for general HTTP use:
- encoding - required for handling UTF-8 responses
- follow_redirects - follow HTTP 30X redirects
- json_request and json_response - encode/decode JSON requests and responses
- parse_dates - parse ISO 8601 dates from response body
- retry - retry intermittent HTTP failures
- url_encoded - encode request body as a url-encoded form upload
Awesome Community Middleware
- cookie_jar - support for HTTP cookies
- detailed_logger - robust logging for requests & responses
- encoding - required for handling UTF-8 responses
- http_cache - standards compliant cache that works with ActiveSupport::Cache
- gzip - decompress responses (needed for some non-default adapters)
- jwt - JWT request encode & response decode with optional signing & verifications
- mashify - parse responses into a Hashie::Mash (for Faraday 2)
Included with faraday
itself
- authorization - middleware for the Authorization HTTP header
- basic_authentication - HTTP basic auth
- instrumentation - instrument requests using ActiveSupport::Notifications or similar
- logger - log request and response
- raise_error - raises exception on 4xx or 5xx
- token_authentication - HTTP token authentication
- url_encoded - encode request body as a url-encoded form upload
- json - encode/decode JSON requests and responses
Bundled into their own gems
- oauth1 - adds an oauth1 access token to each request, via param or header
- multipart - encode request body as a multipart form
- retry - retry intermittent HTTP failures
- rashify - parse responses into a Hashie::Mash::Rash
- follow_redirects - follow HTTP 30X redirects
- encode_xml - encode XML requests (responses decoding is included in
faraday_middleware
gem) - decode_xml - decode XML responses
XML Middleware
- encodes requests as XML, parses response body into a hash of key/value pairs, and provides access to parser/encoder primitives for any custom handling.- aws-xray - records Faraday request spans in AWS X-Ray
faraday_middleware
gem
ATTENTION: faraday_middleware
have been deprecated and won't be updated to work on Faraday 2.0.
All the middleware below will need to be moved into their own gems.
- caching - simple cache that works with ActiveSupport::Cache
- chunked - support for HTTP Transfer-Encoding
- dates - parse ISO 8601 dates from response body
- follow_redirects - follow HTTP 30X redirects
- instrumentation - instruments requests using ActiveSupport::Notifications or similar
- json_fix - fix responses that insist on serving JSON with wrong mime types
- marshal - parse responses as marshalled ruby objects
- method_override - support for X-Http-Method-Override
- oauth/oauth2 - adds an oauth access token to each request
- rashify - parse responses into a Hashie::Rash
- xml - parse responses as XML
- yaml - parse responses as YAML
Has been moved into community gems (see list above):
- mashify
Tooling
- faraday-logging-color_formatter - A color formatter for the default Faraday logger