Skip to content

dblock/grape-on-rack-v1-inside-v2

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
api
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Grape API w/ Versioning Fallback

Build Status

A Grape API mounted on Rack with two versions where v2 builds incrementally on top of v1. In this example the only_in_v1 method is only implemented on version v1, the root method is implemented on both versions, etc.

Run

$ bundle install
$ rackup

Try

# without a version

curl http://localhost:9292/
{"version":"v2"}

curl http://localhost:9292/only_in_v1
{"only_in_v1":"true"}

curl http://localhost:9292/in_both_v1_and_v2
{"in_both_v1_and_v2":"v2"}

# version v2 (current)

Implemented in v2.

curl http://localhost:9292 -H "Accept:application/vnd.acme-v2+json"
{"version":"v2"}

Implemented in v1 and inherited by v2.

curl http://localhost:9292/only_in_v1 -H "Accept:application/vnd.acme-v2+json"
{"only_in_v1":"true"}

Implemented in v2.

curl http://localhost:9292/only_in_v2 -H "Accept:application/vnd.acme-v2+json"
{"only_in_v2":"true"}

curl http://localhost:9292/in_both_v1_and_v2 -H "Accept:application/vnd.acme-v2+json"
{"in_both_v1_and_v2":"v2"}

# version v1 (old)

curl http://localhost:9292 -H "Accept:application/vnd.acme-v1+json"
{"version":"v1"}

curl http://localhost:9292/only_in_v1 -H "Accept:application/vnd.acme-v1+json"
{"only_in_v1":"true"}

curl http://localhost:9292/in_both_v1_and_v2 -H "Accept:application/vnd.acme-v1+json"
{"in_both_v1_and_v2":"v1"}

About

Demonstrate versioning fallback in Grape.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages