Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (28 sloc) 1.141 kb

Faraday Middleware

Collection of Faraday middlewares I've been using in some of my API wrappers

Installation

sudo gem install faraday_middleware

Some examples

Let's decode the response body with MultiJson

conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
  builder.adapter Faraday.default_adapter
  builder.use Faraday::Response::ParseJson
end

resp = conn.get do |req|
  req.url '/users/show.json', :screen_name => 'pengwynn'
end

u = resp.body
u['name']
# => "Wynn Netherland"

Want to ditch the brackets and use dot notation? Mashify it!

conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
  builder.adapter Faraday.default_adapter
  builder.use Faraday::Response::ParseJson
  builder.use Faraday::Response::Mashify
end

resp = conn.get do |req|
  req.url '/users/show.json', :screen_name => 'pengwynn'
end

u = resp.body
u.name
# => "Wynn Netherland"
Jump to Line
Something went wrong with that request. Please try again.