Skip to content

Instantly share code, notes, and snippets.

@bbcoimbra
Forked from tiagomartines/api_constraints.rb
Created June 20, 2013 17:43
Show Gist options
  • Save bbcoimbra/5824902 to your computer and use it in GitHub Desktop.
Save bbcoimbra/5824902 to your computer and use it in GitHub Desktop.
class APIConstraints
def initialize(options)
@version = options[:version]
@default = options[:default]
end
def matches?(request)
@default || request.headers["Accept"].include?("application/vnd.kunto.v#{@version}")
end
end
require "api_constraints"
API::Application.routes.draw do
scope module: :V1, constraints: APIConstraints.new(version: 1, default: true), defaults: { format: :json } do
resources :products
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment