0.0
No commit activity in last 3 years
No release in over 3 years
Rack::Transform is a middleware that attemps to make a compatibility layer between two different request/responses that should hit the same endpoint.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3.2.0, ~> 3.2

Runtime

>= 1.5.0, ~> 1.5
 Project Readme

Rack::Transform

Rack::Transform is a middleware that attemps to make a compatibility layer between two different request/responses that should hit the same endpoint.

The need arouse when migrating an API from PHP to Ruby, where the URLs were different and the response body used to have more metadata that was moved to headers.

Build Status Code Climate


Usage

use Rack::Transform do |map|
  map.on "playlist-get-cues" do |transformer|
    transformer.request = proc do |env|
      ...
    end
    transformer.response = proc do |status, header, body|
      ...
    end
  end

  map.on "search" do |transformer|
    ...
  end
  ...
end

map.on will receive a string that should match the type parameter from the URL and then a block to set the request and response transformers. For more information, see Rack::Transform::Transformer

Rack::Transform::Transformer

Rack:Transform::Transformer intent is to transform rack requests and/or responses into a different format. It can manipulate the request, the response, or both.

Usage:

Transformer.new do |transformer|
  transformer.request = proc do |env|
    ...
  end
  transformer.response = proc do |status, header, body|
    ...
  end
end

request and response methods should receive an object that responds to call, it can be a proc or and object. And they will receive an env object and status, header, body tuple accordingly. Should return the same modified as needed. You can use the base transformers if you prefer to use actual classes instead of procs.

Base Transformer

To help with boilerplate code, base transformer request and response classes were added. More info.

Contributing

See the contributing guide.