Skip to content

add support for versioning using the 'Accept-Version' header#403

Merged
dblock merged 2 commits intoruby-grape:masterfrom
dzrw:feature/support-accept-version-header
May 10, 2013
Merged

add support for versioning using the 'Accept-Version' header#403
dblock merged 2 commits intoruby-grape:masterfrom
dzrw:feature/support-accept-version-header

Conversation

@dzrw
Copy link
Copy Markdown
Contributor

@dzrw dzrw commented May 10, 2013

We'd like to be able to version our REST-like APIs using the Accept-Version header. This patch adds support and specs for the :accept_version_header strategy.

curl -H "Accept-Version=v1" http://localhost:9292/api/toys

Grape::Middleware::Versioner does not expose the ability to register a custom versioning strategy, and this patch does not attempt to create a registration mechanism. We simply use the existing case switcher to plug-in a new strategy.

Although the Accept-Version header is not a part of RFC 2616, various companies and frameworks follow the version header approach (e.g. http://mcavage.github.io/node-restify/). There are pros and cons to all of the currently popular versioning strategies (URI, Conneg, query strings), and the Accept-Version header is just one of many solutions to the various trade-offs.

@dblock
Copy link
Copy Markdown
Member

dblock commented May 10, 2013

I like it. Code looks great. Please update CHANGELOG and document the new strategy in the README.

@dzrw
Copy link
Copy Markdown
Contributor Author

dzrw commented May 10, 2013

Thanks, I've updated the changelog and added documentation.

@dblock
Copy link
Copy Markdown
Member

dblock commented May 10, 2013

Nice work.

dblock added a commit that referenced this pull request May 10, 2013
…n-header

add support for versioning using the 'Accept-Version' header
@dblock dblock merged commit 675cb9e into ruby-grape:master May 10, 2013
@stevegraham
Copy link
Copy Markdown

Wouldn't this be ignored by caching layers?

@dblock
Copy link
Copy Markdown
Member

dblock commented Nov 15, 2013

@stevegraham You have a point. Practically though most APIs likely don't care as they don't set content expiration headers. Not sure whether we should have not merged this, but the caveat is important.

@stevegraham
Copy link
Copy Markdown

@dblock I thought of a solution. If the server adds the header Vary: Accept-Version it should be properly cacheable.

@dblock
Copy link
Copy Markdown
Member

dblock commented Nov 15, 2013

So maybe this should be documented. Would love a pull request as a note to the feature?

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

Successfully merging this pull request may close these issues.

3 participants