Various Faraday middlewares for Faraday-based API wrappers
Clone or download

Faraday Middleware

A collection of useful Faraday middleware. See the documentation.

gem install faraday_middleware


Some dependent libraries are needed only when using specific middleware:

Middleware Library Notes
FaradayMiddleware::Instrumentation activesupport
FaradayMiddleware::OAuth simple_oauth
FaradayMiddleware::ParseXml multi_xml
FaradayMiddleware::ParseYaml safe_yaml Not backwards compatible with versions of this middleware prior to faraday_middleware v0.12. See code comments for alternatives.
FaradayMiddleware::Mashify hashie
FaradayMiddleware::Rashify rash_alt Make sure to uninstall original rash gem to avoid conflict.


require 'faraday_middleware'

## in Faraday 0.8 or above:
connection = '' 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

## with Faraday 0.7:
connection = '' 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