Versioning ignores HTTP method, only matches on route name.

Open
#1,782 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
api

Research direction

Start by reproducing the issue with the shown Grape::API route definitions and the four curl requests, comparing the v2 GET and POST results with the expected responses. The work is done when version 2 matches both the route version and HTTP method, returning "baz" for GET and "qux" for POST.

Written by the indexing model from the issue text.

Description

bug?

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"
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby-grape/grape

All issues in ruby-grape/grape

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.