Class: ApiSampler::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/api_sampler/middleware.rb

Overview

This class provides rack-compatible middleware to collect and tag API endpoint samples.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware


9
10
11
# File 'lib/api_sampler/middleware.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/api_sampler/middleware.rb', line 13

def call(env)
  status, headers, response = @app.call(env)
  request = ActionDispatch::Request.new(env)

  resolve_route(request) do |route|
    break unless allowed?(request)

    sample = collect_sample(route, request, response)
    tag(sample, request)
  end

  [status, headers, response]
end