Project

ur

0.0
A long-lived project that still receives updates
ur provides a unified representation of a request and response. it can be interpreted from rack, faraday, or potentially other sources, and provides a consistent interface to access the attributes inherent to the request and additional useful parsers and computation from the request.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.8.1
 Project Readme

Ur áš’

Ur: Unified Request/Response Representation in Ruby

Properties

An ur primarily consists of a request, a response, and additional metadata.

The request consists of the request method, uri, headers, and body.

The response consists of the response status, headers, and body.

The metadata consist of the time the request began, the duration of the request, or tag strings. This is optional.

Other attributes may be present, and are ignored by this library.

Usage with middleware

Rack middleware:

class MyRackMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    # do things before the request

    ur = Ur.from_rack_request(env)

    # set additional properties of the ur, for example:
    ur.logger_tags(my_logger)

    rack_response = ur.with_rack_response(@app, env) do
      # do things after the response
    end
    rack_response
  end
end

Faraday middleware:

class MyFaradayMiddleware < ::Faraday::Middleware
  def call(request_env)
    # do things before the request

    ur = Ur.from_faraday_request(request_env)

    # set additional properties of the ur, for example:
    ur.logger_tags(my_logger)

    ur.faraday_on_complete(@app, request_env) do |response_env|
      # do things after the response
    end
  end
end

License

Ur is licensed under the terms of the GNU Lesser General Public License version 3.