Class Grape::Middleware::Versioner::Header
In: lib/grape/middleware/versioner/header.rb
Parent: Base

This middleware sets various version related rack environment variables based on the HTTP Accept header with the pattern: application/vnd.:vendor-:version+:format

Example: For request header

   Accept: application/vnd.mycompany.a-cool-resource-v1+json

The following rack env variables are set:

   env['api.type']    => 'application'
   env['api.subtype'] => 'vnd.mycompany.a-cool-resource-v1+json'
   env['api.vendor]   => 'mycompany.a-cool-resource'
   env['api.version]  => 'v1'
   env['api.format]   => 'json'

If version does not match this route, then a 406 is raised with X-Cascade header to alert Grape::Router to attempt the next matched route.

Methods

before  

Constants

VENDOR_VERSION_HEADER_REGEX = /\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))?(?:\+([a-z0-9*\-.]+))?\z/
HAS_VENDOR_REGEX = /\Avnd\.[a-z0-9.\-_!#\$&\^]+/
HAS_VERSION_REGEX = /\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))+/

Public Instance methods

[Validate]