Skip to content

Instantly share code, notes, and snippets.

@slowjud
Created May 1, 2014 06:15
Show Gist options
  • Save slowjud/29cf08db413453fe83cb to your computer and use it in GitHub Desktop.
Save slowjud/29cf08db413453fe83cb to your computer and use it in GitHub Desktop.
Version Accept headers
class ApiConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
def matches?(req)
@default || req.headers['Accept'].include?("application/vnd.betterbills.v#{@version}")
end
end
ApiService::Application.routes.draw do
namespace :person_service, defaults: {format: 'json'} do
scope module: :v1, constraints: ApiConstraints.new(version: 1) do
get '/people', to: 'people#index'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment