Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable incrementally building on top of a previous API version #442

Closed
dblock opened this issue Jul 19, 2013 · 1 comment
Closed

Enable incrementally building on top of a previous API version #442

dblock opened this issue Jul 19, 2013 · 1 comment

Comments

@dblock
Copy link
Member

dblock commented Jul 19, 2013

API v1

module Acme
  class V1 < Grape::API
    format :json
    version [ 'v2', 'v1' ], using: :header, vendor: 'acme', format: :json, cascade: true

    desc "Returns the current API version, v1."
    get do
      { version: 'v1' }
    end

    desc "Returns pong."
    get "ping" do
      { ping: "pong" }
    end
  end
end

API v2

module Acme
  class V2 < Grape::API
    format :json
    version 'v2', using: :header, vendor: 'acme', format: :json, cascade: true

    desc "Returns the current API version, v2."
    get do
      { version: 'v2' }
    end
  end
end

We should be able to mount these in v2, then v1 order, like so:

Rack::Cascade.new([ Acme::V2, Acme::V1 ])

Then V2 will respond to API requests that it implements, and V1 will respond to anything remaining, since it also supports v2.

@dblock
Copy link
Member Author

dblock commented Jul 19, 2013

Fixed in 2be499c and wrote an example of how to fallback to the implementation of a previous version: https://github.com/dblock/grape-on-rack-v1-inside-v2.

@dblock dblock closed this as completed Jul 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant