N
Nuxt7mo ago
w7a9q

Get body of the response

I'm trying to get the body of the response through H3. readBody() is only for request body. How do I get the one from response?
9 Replies
manniL
manniL7mo ago
@w7a9q what do you mean with "the reponse body"?
w7a9q
w7a9qOP7mo ago
HTTP response body
manniL
manniL7mo ago
I got that. but of which response? Can you show some code Because at the point when you read the body, it is always the body of the request some client sent to the nitro endpoint
w7a9q
w7a9qOP7mo ago
Yeah but you can use middleware to manipulate with the response as well, right? I don't have any code. I want to write a middleware and read the body of the response I return back from endpoint implemented in the server/api.
manniL
manniL7mo ago
ah, so a middleware after handling the request then? What is the use case if I may ask
w7a9q
w7a9qOP7mo ago
The client wants us to verify that the actual response body is JSON.
manniL
manniL7mo ago
Plugins - Nitro
Use plugins to extend Nitro's runtime behavior.
manniL
manniL7mo ago
check out beforeResponse
w7a9q
w7a9qOP7mo ago
Great! Thanks

Did you find this page helpful?