Access response_object/@body return in after filter
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
I am attempting to implement API versioning ala Stripe (https://stripe.com/blog/api-versioning).
I currently have a working prototype that hooks into Grape before/after hooks – but to modify the response I have to reparse and regenerate the JSON from response.body – when obviously I would prefer to hook in earlier and muck with the hash before it's jsonified – it also means I have to correct the headers e.g. Content-Length, if I want those to be correct.
I see in https://github.com/ruby-grape/grape/blob/master/lib/grape/endpoint.rb#L262-L265 you now assign response_object to @body but not until after the after hooks have fired.
Is there a way for me to get at this?
Is there a reason I shouldn't?
Is there a reason @body shouldn't be assigned sooner?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/grape/endpoint.rb around lines 262-265 and trace how response_object, @body, and the before/after hooks are ordered. Determine whether the after hook can expose the pre-JSONified response safely, then verify that the resulting response body and headers remain consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100