Class: Rack::Kibo

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/kibo/kibo.rb,
lib/rack/kibo/version.rb

Overview

Rack Middleware which presents a clean API to JSON responses

Constant Summary collapse

API_PARSE_REGEX =

Regex to locate an API version in the path. Able to find the following

  • /path/api/1/something => 1

  • /path/api/V2/something => 2

  • /api/v13/omething => 13

  • /something/else/134/ => 0

/.*\/api\/[vV]?(\d*)\/?/
JSON_CONTENT_TYPE =

Standard JSON content-type

"application/json"
JSON_CONTENT_TYPE_REGEX =
/application\/json/
VERSION =
"0.1.3"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Kibo

Creates a new instance of the CleanApi middleware app: The rack app options: Hash of options to pass to the middleware



24
25
26
27
# File 'lib/rack/kibo/kibo.rb', line 24

def initialize(app, options={})
  @app = app
  @options = options
end

Instance Method Details

#call(env) ⇒ Object

Rack Middleware entry-point



31
32
33
34
35
36
# File 'lib/rack/kibo/kibo.rb', line 31

def call(env)
  result = @app.call(env)
  wrap_response env, result
rescue StandardError => e
  wrap_response env, create_error_response(e, env, result)
end