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

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

Merged
merged 2 commits into from
May 10, 2013

Conversation

dzrw
Copy link
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
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
Contributor Author

dzrw commented May 10, 2013

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

@dblock
Copy link
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

Wouldn't this be ignored by caching layers?

@dblock
Copy link
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

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

@dblock
Copy link
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