Class: Grape::Middleware::Versioner::Header
- Includes:
- Grape::Middleware::VersionerHelpers
- Defined in:
- lib/grape/middleware/versioner/header.rb
Overview
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.
Constant Summary
Constants included from Grape::Middleware::VersionerHelpers
Grape::Middleware::VersionerHelpers::DEFAULT_PARAMETER, Grape::Middleware::VersionerHelpers::DEFAULT_PATTERN
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods included from Grape::Middleware::VersionerHelpers
#cascade?, #default_options, #error_headers, #mount_path, #parameter_key, #pattern, #potential_version_match?, #prefix, #strict?, #vendor, #version_options, #versions
Methods inherited from Base
#after, #call, #call!, #content_type, #content_type_for, #content_types, #default_options, #initialize, #mime_types, #response
Methods included from DSL::Headers
Methods included from Helpers
Constructor Details
This class inherits a constructor from Grape::Middleware::Base
Instance Method Details
#before ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grape/middleware/versioner/header.rb', line 27 def before match_best_quality_media_type! do |media_type| env.update( Grape::Env::API_TYPE => media_type.type, Grape::Env::API_SUBTYPE => media_type.subtype, Grape::Env::API_VENDOR => media_type.vendor, Grape::Env::API_VERSION => media_type.version, Grape::Env::API_FORMAT => media_type.format ) end end |