Open stevelacey opened 6 years ago
I don't see an immediate reason why you shouldn't have access to the response body in after
, feel free to PR.
@dblock I am not entirely sure how it'd work if I simply move that line up – I can probably edit the @body
hash by reference but that seems weird
Am I right in assuming that others are mostly using these hooks for injecting headers and stuff? Is request/response manipulation more significant than that a case you want to support? I intend to adjust params going in and json coming out
I think you should definitely be able to modify the response body on the way out other than in a middleware, so please PR something with tests, etc.
Also, any suggestions how to get at params
? A use-case I intend to support is renaming params coming in to the system. Maybe I want Rack middleware rather than Grape..
Params can be modified in before
AFAIK.
@dblock only env
is available... and I'm not sure how to pull params out of that and/or put them back in a meaningful way – do I need a pass through params builder?
Right but does modifying though achieve anything? On Fri, 27 Oct 2017 at 20:49, Daniel Doubrovkine (dB.) @dblockdotorg < notifications@github.com> wrote:
Is this already run? https://github.com/ruby-grape/grape/blob/91c6c78ae3d3f3ffabaf57ffc4dc35ab7cfc7b5f/lib/grape/middleware/globals.rb
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ruby-grape/grape/issues/1695#issuecomment-339976707, or mute the thread https://github.com/notifications/unsubscribe-auth/AARq-1nxScsBOLAFDDoISMeeuFMAycYnks5swd92gaJpZM4QD5Xn .
I am not sure. Try to build specs for what you're trying to achieve and I can see if I have time to help.
@dblock global doesn't appear to have run, should it have?
Don't know, most of this was refactored in the last 3-4 versions of Grape and i haven't touched much code. Sorry i can't be more helpful.
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 theafter
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?