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

Versioning ignores HTTP method, only matches on route name. #1782

Open
coreystinson2 opened this issue Aug 22, 2018 · 5 comments
Open

Versioning ignores HTTP method, only matches on route name. #1782

coreystinson2 opened this issue Aug 22, 2018 · 5 comments
Labels

Comments

@coreystinson2
Copy link

When defining the same routes under different versions, the version 2 routes are not matching on the http method, it appears that they're only looking at the name.

class API < Grape::API

  version "v1", using: :accept_version_header

  get "/" do
    return "foo"
  end

  post "/" do
    return "bar"
  end

  version "v2", using: :accept_version_header

  get "/" do
    return "baz"
  end

  post "/" do
    return "qux"
  end

end
curl -X GET http://localhost:3000/
=> "foo"

curl -X POST http://localhost:3000/
=> "bar"

curl -X GET http://localhost:3000/ --header "Accept-Version:v2"
=> "qux"
# it is expected that this returns "baz"

curl -X POST http://localhost:3000/ --header "Accept-Version:v2"
=> "qux"
@coreystinson2
Copy link
Author

Added a third DELETE route under the version2 definition and now GET and POST verbs are matching to this. It appears to be matching only to the last-defined route ?

delete "/" do
  return "quux"
end

@dblock
Copy link
Member

dblock commented Aug 22, 2018

This looks suspiciously simple for a bug, but Accept-Version is not widely used, so who knows. Try to see what specs we have for this and turn this one into a failing one?

@dblock dblock added the bug? label Aug 22, 2018
@coreystinson2
Copy link
Author

Sure, i'll take a look and see what I can find.
Is the default path strategy a more "preferred" method of achieving versioning with grape ?

@dblock
Copy link
Member

dblock commented Aug 22, 2018

I would say the HTTP way is :header, check out https://code.dblock.org/2013/07/19/evolving-apis-using-grape-api-versioning.html

@nickrivadeneira
Copy link

I opened #1799 which I believe to be related and contains some analysis and suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants