ruby - get response of grape endpoint with def after -


i'm using grape. want define method runs after response value has been calculated request, tried following this:

http://www.sinatrarb.com/intro.html#filters

and ended with:

after   puts response end 

however response not defined. apparently within block, self refers grape::endpoint, since after runs after endpoint handler, should able find response value, right? tried self.body returns nothing - does, however, let me change value of response, want retrieve response value generated handler.

ahh, solved using rack middleware:

class captureresponse < grape::middleware::base     def call!(env)         @env = env         @app_response = @app.call(@env)         body = @app_response[2]         body = body.body if body.kind_of? rack::bodyproxy         puts body         @app_response     end end use captureresponse 

i have no idea why slapping in use captureresponse in config.ru works does!


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -