ruby-grape / ruby-grape/grape

Support different incoming to outgoing content-type

Open
#1,697 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss! feature request
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue's v1 configuration with the listed parser, formatter, error formatter, and ActiveModelSerializers integration, while referencing the behavior introduced by #1589. Trace how the incoming application/merge-patch+json type determines the outgoing response type. Done means accepting merge-patch requests while responses use application/json without the current boilerplate.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.