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

Support different incoming to outgoing content-type #1697

Open
stevelacey opened this issue Oct 26, 2017 · 1 comment
Open

Support different incoming to outgoing content-type #1697

stevelacey opened this issue Oct 26, 2017 · 1 comment

Comments

@stevelacey
Copy link

stevelacey commented Oct 26, 2017

I am attempting to upgrade to v1 and have been banging my head against problems caused by #1589

We do some JSON Merge Patch – prior to #1589 that was as simple as:

if request.content_type == 'application/merge-patch+json'
  # do something different
end

Now I have to do some of this to dodge 406's

content_type :json_merge_patch, 'application/merge-patch+json'
format :json_merge_patch
formatter :json_merge_patch, Grape::Formatter::ActiveModelSerializers
error_formatter :json_merge_patch, ACME::JsonErrorFormatter
parser :json_merge_patch, Grape::Parser::Json

And this works, but now the API serves out Content-Type: application/merge-patch+json – but it should still be application/json, the request was partial but the response is full.

I expect I need to adjust the formatter to do this... but given ours is ActiveModelSerializers it's pretty abstract and I am not sure where JSON comes into it.

Is there really the need for all of this boilerplate to do this?

@dblock
Copy link
Member

dblock commented Oct 26, 2017

Just to rephrase the problem, given an incoming content type you want a different outgoing content type. Generally that seems pretty simple, you declare a formatter for the outgoing content type then set the content type inside that if. Is that not working? Care to try and produce a spec that shows what you're trying to accomplish and we can simplify it and possibly add some code to avoid the boilerplate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants