Illustrates how path and header versioning can be used side by side for different versions. See this blog post for the original discussion
To run example:
bundle
ruby api.rb
Illustrates how path and header versioning can be used side by side for different versions. See this blog post for the original discussion
To run example:
bundle
ruby api.rb
require 'bundler' | |
Bundler.require :default | |
require 'grape' | |
require 'rack-test' | |
class API < Grape::API | |
version 'v2', using: :header, vendor: 'example' | |
get '/hello' do | |
"I am version 2" | |
end | |
version 'v1', using: :path | |
get '/hello' do | |
"I am version 1" | |
end | |
end | |
include Rack::Test::Methods | |
def app | |
API | |
end | |
get '/v1/hello' | |
puts "with path version v1: " + last_response.body | |
puts | |
get '/hello' | |
puts "with no version specified in header, defaults to latest available version: " + last_response.body | |
puts | |
get '/hello', {}, {'HTTP_ACCEPT' => 'application/vnd.example-v2+txt'} | |
puts "with header version v2: " + last_response.body | |
puts |
source 'http://rubygems.org' | |
gem 'grape', :git => '[email protected]:intridea/grape.git' | |
gem 'rack' | |
gem 'rack-test' |