-
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Added versioning based on accept headers #69
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
Conversation
Added Travis badge and removed Gemfile.lock
Sorry, stole it from some other project and must have accidentally left it as linking to that project!
Fix for Travis badge
This allows Grape to work with ActiveResource in JSON mode. If the body contains JSON, it's contents will be added to the params hash just like if they came over the GET query string or as regular params.
Didn't account for regular POST content being in the body on some requests, even if JSON is expected as the result. It now fails gracefully.
Content type for error response
added http digest auth
Conflicts: lib/grape/middleware/formatter.rb
Ability to handle incoming JSON in the body
Got rid of .yarddoc and updated readme to clarify exception handling.
Exposing the set of rack routes built by Grape
Fix README code snippet
Call #to_xml if the content type is xml
Ability to handle incoming XML in the body
fixed rescue_from, broken when trying to rescue multiple specific exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You meant to do this with vendor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended to add this spec right underneath it:
it 'should use HTTP_ACCEPT headers when a vendor is set' do
subject.get :hello do
"Hello"
end
subject.vendor 'grape' subject.version 'v1' subject.get :hello do "World" end header 'Accept', 'application/vnd.grape-v1+json' get '/hello' last_response.status.should eql 200 last_response.body.should eql 'World' header 'Accept', 'application/vnd.grape-v1+json' get '/v1/hello' last_response.status.should eql 404 end` The last get should fail, because it defines a double version, comparable to /v1/v1/hello, which isn't defined
| @mbleigh should look at this pull, thx |
| I love this feature and definitely want it in, however, I'd like to ask for a small implementation change. Rather than adding a class MyAPI < Grape::API version 'v1', :allow => [:header, :path], :vendor => 'grapeinc' endWhere the vendor is specified inline (and would simply default to the API classname if not specified). By default the I can do the change myself in the next few days, but I'd also appreciate if someone else did it for me :) |
| @mbleigh I like the inline syntax, but the class OldAPI < Grape::API version 'v1', :via => :path, :vendor => 'grapeinc' end class NewAPI < Grape::API version 'v2', :via => :header, :vendor => 'grapeinc' endThis allows API's to transition to a new versioning strategy, similar to how Github's API moved from One gotcha with defaulting |
| I'm 👍 for using only one or the other, but let's call it |
To call a method on a specific API version, instead of using
GET /
<version>/<resource>/action, one could useGET /
<resource>/action, while supplying an HTTP Accept header:application/vnd.
<vendor>-<version>+<format>This way it is possible to keep the URL RESTful
To use this functionality one would use:
class MyAPI < Grape::API
vendor 'grapeinc'
version 'v1.1'
get '/someaction' do
{:hello => 'world'}
end
end
To call this api, one would, for instance do
curl http://localhost:9292/someaction -H "Accept: application/vnd.grapeinc-v1.1+json"