Middleware to intercept responses #306
patrickvuarnoz
started this conversation in
Ideas
Replies: 1 comment
-
For my current use case with logging I found a workaround as it is also possible to log the response AFTER it has been sent. It's not a clean solution but I'll post it here in case somebody else is having the same issue. Still, being able to not only intercept the request but also the response would be helpful. And being able to access the response properties without reflection would also be helpful (i.e. add getters for status, content, headers).
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, as far as I can see, in Leaf 4 it is only possible to use middleware to intercept requests and perform actions and checks before the route gets called. It would be helpful if a middleware could also be used to intercept a response before it is sent to the client.
My current use case is logging. Logging the requests is simple with the current possibilities of the middleware. But depending on the status code of the response I also want to log the response, i.e. for all 4xx and 5xx responses, to be able to provide better support when API users contact the support about the problem. I don't want to add code for this kind of logging in all program parts where 4xx responses are sent and I don't want to replace
response()->json()
with a custom method for this.I imagine something like
Middleware::before()
undMiddleware::after()
would be useful. One being called before routing happens, one after the routing beforeResponse::send()
is called. Another option would be to allow to create interceptors for responses with something likeResponse::onBeforeSend(function () {})
.Would it be possible to extend Leaf to be able to handle this?
Beta Was this translation helpful? Give feedback.
All reactions