Class: Grape::Middleware::Versioner::Path

Overview

This middleware sets various version related rack environment variables
based on the uri path and removes the version substring from the uri
path. If the version substring does not match any potential initialized
versions, a 404 error is thrown.

Example: For a uri path
/v1/resource

The following rack env variables are set and path is rewritten to
'/resource':

Constructor Details

Instance Method Details

# File 'lib/grape/middleware/versioner/path.rb', line 26defbeforepath=env['PATH_INFO'].dupifprefix&&path.index(prefix)==0path.sub!(prefix,'')path=Rack::Mount::Utils.normalize_path(path)endpieces=path.split('/')potential_version=pieces[1]ifpotential_version=~options[:pattern]ifoptions[:versions]&&!options[:versions].find{|v|v.to_s==potential_version}throw:error,status:404,message:'404 API Version Not Found'endenv['api.version']=potential_versionendend