Class: Grape::Middleware::Versioner::AcceptVersionHeader
- Defined in:
- lib/grape/middleware/versioner/accept_version_header.rb
Overview
This middleware sets various version related rack environment variables based on the HTTP Accept-Version header
Example: For request header
Accept-Version: v1
The following rack env variables are set:
env['api.version'] => 'v1'
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 inherited from Base
Base::CASCADE_PASS_HEADER, Base::DEFAULT_OPTIONS
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
inherited, #initialize, #potential_version_match?, #version_not_found!
Methods inherited from Base
#after, #call, #call!, #content_type, #content_type_for, #content_types, #context, #initialize, #mime_types, #query_params, #rack_request, #response
Methods included from DSL::Headers
Constructor Details
This class inherits a constructor from Grape::Middleware::Versioner::Base
Instance Method Details
#before ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/grape/middleware/versioner/accept_version_header.rb', line 20 def before potential_version = env['HTTP_ACCEPT_VERSION'].try(:scrub) not_acceptable!('Accept-Version header must be set.') if strict && potential_version.blank? return if potential_version.blank? not_acceptable!('The requested version is not supported.') unless potential_version_match?(potential_version) env[Grape::Env::API_VERSION] = potential_version end |