Class Grape::API::Instance
In: lib/grape/api/instance.rb
Parent: Object

The API Instance class, is the engine behind Grape::API. Each class that inherits from this will represent a different API instance

Methods

base=   call   call   call!   cascade   cascade?   change!   compile   inherit_settings   inherited   nest   new   prepare_routes   recognize_path   reset!   to_s  

Included Modules

Grape::DSL::API

Constants

LOCK = Mutex.new   A class-level lock to ensure the API is not compiled by multiple threads simultaneously within the same process.

Attributes

base  [R] 
configuration  [RW] 
instance  [R] 
router  [R] 

Public Class methods

This is the interface point between Rack and Grape; it accepts a request from Rack and ultimately returns an array of three values: the status, the headers, and the body. See [the rack specification] (www.rubydoc.info/github/rack/rack/master/file/SPEC) for more.

A non-synchronized version of ::call.

Wipe the compiled API so we can recompile after changes were made.

Parses the API‘s definition and compiles it into an instance of Grape::API.

Builds the routes from the defined endpoints, effectively compiling this API into a usable form.

Clears all defined routes, endpoints, etc., on this API.

Protected Class methods

Execute first the provided block, then each of the block passed in. Allows for simple ‘before’ setups of settings stack pushes.

Public Instance methods

Handle a request. See Rack documentation for what `env` is.

Some requests may return a HTTP 404 error if grape cannot find a matching route. In this case, Grape::Router adds a X-Cascade header to the response and sets it to ‘pass’, indicating to grape‘s parents they should keep looking for a matching route on other resources.

In some applications (e.g. mounting grape on rails), one might need to trap errors from reaching upstream. This is effectivelly done by unsetting X-Cascade. Default :cascade is true.

[Validate]