Skip to content

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

Closed
@dblock

Description

@dblock

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions