New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

faraday-stack

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faraday-stack

  • 0.1.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Über Stack

Notice: faraday-stack has been deprecated and its middleware moved to faraday_middleware.


Faraday is an HTTP client lib that provides a common interface over many adapters (such as Net::HTTP) and embraces the concept of Rack middleware when processing the request/response cycle.

“Faraday Stack” is an add-on library that implements several middleware (such as JSON and XML parsers) and helps you build an awesome stack that covers most of your API-consuming needs.

Boring example:

require 'faraday_stack'

response = FaradayStack.get 'http://google.com'

response.headers['content-type']  #=> "text/html; charset=UTF-8"
response.headers['location']      #=> "http://www.google.com/"
puts response.body

Awesome example:

conn = FaradayStack.build 'http://github.com/api/v2'

# JSON resource
resp = conn.get 'json/repos/show/mislav/faraday-stack'
resp.body
#=> {"repository"=>{"language"=>"Ruby", "fork"=>false, ...}}

# XML resource
resp = conn.get 'xml/repos/show/mislav/faraday-stack'
resp.body.class
#=> Nokogiri::XML::Document

# 404
conn.get 'zomg/wrong/url'
#=> raises Faraday::Error::ResourceNotFound

Features

  • parses JSON, XML & HTML
  • raises exceptions on 4xx, 5xx responses
  • follows redirects

To see how the default stack is built, see "faraday_stack.rb".

Optional features:

  • encode POST/PUT bodies as JSON:

      conn.post(path, payload, :content_type => 'application/json')
    
  • add Instrumentation middleware to instrument requests with ActiveSupport

      conn.builder.insert_after Faraday::Response::RaiseError, FaradayStack::Instrumentation
    
  • add Caching middleware to have GET responses cached

      conn.builder.insert_before FaradayStack::ResponseJSON, FaradayStack::Caching do
        ActiveSupport::Cache::FileStore.new 'tmp/cache',
          :namespace => 'faraday', :expires_in => 3600
      end
    
  • mount Rack::Cache through RackCompatible middleware for HTTP caching of responses

      conn.builder.insert_after FaradayStack::FollowRedirects, FaradayStack::RackCompatible,
        Rack::Cache::Context,
          :metastore   => "file:/var/cache/rack/meta",
          :entitystore => "file:/var/cache/rack/body"
    

FAQs

Package last updated on 29 Jan 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc