-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
default_format :json not working #407
Comments
This is actually not a bug, but it did take a me a while to figure out what's going on. You're posting data to the server. Since you don't specify that the data is JSON, Grape doesn't parse it. If you say So what's
and otherwise?
The key is the body, the value is
That's what's returned from the API. I am happy to discuss whether |
I convinced myself that the most logical thing to do would be to apply |
Still behaving like this for me...format and default_format are :json yet this same exact thing is still happening without Content-Type.
results in:
Looks like the format to parse with is being set to whatever the request's media type is, which is defaulting to "application/x-www-form-urlencoded"
from
So it never sets it to options[:default_format] |
Try to (re)write a spec like this @csoreff and PR it? Maybe with a fix? |
The test doesn't handle when content type isn't supplied at all, it's given as a blank string:
When I remove that content type and post without it, it breaks without even making it to #read_rack_input and test fails. These are both false in #read_body_input so it returns here:
request.media_type defaulted to "application/x-www-form-urlencoded", same as my earlier example, a default setting from Rails I believe. I'll look at it more later. Not sure off the top of my head on how to solve this on Grape's side, since at this point we can't really differentiate between a defaulted media type and if that was actually the type given for form data (unless there's a way to check the exact original request?). |
You should reopen this as a new issue. |
Re-reading this, POST with a default content type is not a thing for Rack, it won't parse input as you can see. However, Grape could apply |
Grape can't apply default_format because it doesn't even make it to the point where it does so. |
@csoreff We could make it get there, right? ;) |
Oh haha yea, I suppose I read that wrong. :P |
Hi,
I am playing with https://github.com/djones/grape-goliath-example . My current API class looks like:
The original version of example is using grape 0.2.2, where both call shown below work as expected. When updated the 0.4.1 (bundle update grape) the following call works:
returning
but when application/json is ommited
the call returns
The text was updated successfully, but these errors were encountered: