-
Notifications
You must be signed in to change notification settings - Fork 203
Home
Olle Jonsson edited this page Feb 24, 2020
·
8 revisions
(Please note: This wiki has been closed, and turned into in-repo Markdown
documents. You can find them in the repository's docs/
directory. This wiki does not take new edits.)
This is a collection of middleware for the Faraday project. See what changed in faraday_middleware 0.8
Example use:
require 'faraday_middleware'
## in Faraday 0.8 or above:
connection = Faraday.new 'http://example.com/api' do |conn|
conn.request :oauth2, 'TOKEN'
conn.request :json
conn.response :xml, :content_type => /\bxml$/
conn.response :json, :content_type => /\bjson$/
conn.use :instrumentation
conn.adapter Faraday.default_adapter
end
## with Faraday 0.7:
connection = Faraday.new 'http://example.com/api' do |builder|
builder.use FaradayMiddleware::OAuth2, 'TOKEN'
builder.use FaradayMiddleware::EncodeJson
builder.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/
builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
builder.use FaradayMiddleware::Instrumentation
builder.adapter Faraday.default_adapter
end
Important: same as with Rack middleware, the order of middleware on a Faraday stack is significant. General guidelines:
- put request middleware first, in order of importance;
- put response middleware second, in the reverse order of importance;
- ensure that the adapter is always last.
- FaradayMiddleware::EncodeJson
- FaradayMiddleware::OAuth
- FaradayMiddleware::OAuth2
- FaradayMiddleware::MethodOverride
-
Parsing responses:
- FaradayMiddleware::ParseJson
- FaradayMiddleware::ParseXml
- FaradayMiddleware::ParseYaml
- FaradayMiddleware::ParseMarshal
- FaradayMiddleware::Caching
- FaradayMiddleware::FollowRedirects
- FaradayMiddleware::Mashify
- FaradayMiddleware::Rashify
(Please note: This wiki has been closed, and turned into in-repo Markdown
documents. You can find them in the repository's docs/
directory. This wiki does not take new edits.)