Project

apis

0.0
No commit activity in last 3 years
No release in over 3 years
Rack-like HTTP client library inspired by Faraday done my way
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Usage

connection = Apis::Connecton.new(:url => 'http://api.example.com') do
  use Apis::Request::JSON
  use Apis::Request::OAuth2
  use Apis::Request::Logger
  adapter Apis::Adapter::NetHTTP
end
	
connection.get('/hello')

Specification

Middleware

Middleware is object that responds to call, accepts env hash and returns array with three elements in order: status, headers, body.

Middleware should accept application it decorates as first parameter to initializer.

Example middleware:

class Middleware
  def initialize(app)
    @app = app
  end
  
  def call(env)
    # do something with request
    response = @app.call(env) # it's decorator, you are responsible to forward message to decorated app
    # do something with response
    response
  end
end

Environment

  • :method - uppercased request method, should be one of: :GET, :POST, :PUT, :DELETE
  • :uri - parsed URi, instance of Addressable::URI
  • :params - params to be sent, instance of Hash
  • :body - body to be sent. If set than :params are not used
  • :headers - headers to be sent, instance of Hash