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

format :json parses other content-types than application/json (eg. application/x-www-form-urlencoded) #1403

Open
ciaoben opened this issue May 19, 2016 · 7 comments
Labels

Comments

@ciaoben
Copy link

ciaoben commented May 19, 2016

I want my API to accept only application/json as a Content-Type. Reading the docs it seems that this should do the work:

class BaseApi < Grape::API
  format :json
  prefix :api
end

but my API still accept other Content-Types

@dblock
Copy link
Member

dblock commented May 20, 2016

It's slightly more complicated, the doc says:

screen shot 2016-05-20 at 7 12 40 am

What content-type are you sending that is not producing a 406? If it's none of the above, try turning this into a spec?

@dblock dblock added the bug? label May 20, 2016
@ciaoben
Copy link
Author

ciaoben commented May 26, 2016

I will do it as soon as possibile

@ciaoben
Copy link
Author

ciaoben commented May 26, 2016

@dblock
I am having problem pushing my specs to the repo, I followed the steps of CONTRIBUTING.md but it gives me:

remote: Permission to ruby-grape/grape.git denied to ciaoben.
fatal: unable to access 'https://github.com/ruby-grape/grape.git/': The requested URL returned error: 403

@dblock
Copy link
Member

dblock commented May 26, 2016

You should make changes and push to your fork, not to this repo, this should be helpful.

ciaoben added a commit to ciaoben/grape that referenced this issue May 26, 2016
I have created an example that shows that even if it is setted `format :json`, if I send a post request with content_type: application/x-www-form-urlencoded it does return `201`
@ciaoben
Copy link
Author

ciaoben commented May 26, 2016

Thanks, I have created the PR, sorry but I had never done it.

@dblock
Copy link
Member

dblock commented May 26, 2016

This works by design, the documentation is correct. A JSON API does parse application/x-www-form-urlencoded date. I would be curious to see what a PR "fixing" this looks like, and would like to open it for discussion.

@dblock dblock changed the title format :json does not seem to work as documented format :json parses other content-types than application/json (eg. application/x-www-form-urlencoded) May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants