Polka: Can I take response body?

Created on 15 May 2019  Â·  10Comments  Â·  Source: lukeed/polka

I want to log the processing-elapsed-time and response body.
Is there have something like a after-response-hook?

question

All 10 comments

Hey there,

Parsing the response body comes from a middleware like body-parser or Polka's recent @polka/parse, which can be installed via npm install @polka/parse@next for now.

Not sure exactly what the first part of your question is to be honest. Are you trying to measure the elapsed time for parsing the request body, or trying to measure the elapsed time for the whole response cycle?

If the latter, there are a number of libraries that do this for you; like morgan for example – and see examples/with-morgan. Here's an example from sirv-cli that does the same thing without any library (no Polka/middleware though).

I don't know of any parsers that specifically measure the time needed to parse the request body. You'd probably have to do that yourself by wrapping body-parser or @polka/parse directly.

Hope that helps!

Hello @lukeed

Are you going to proceed development of @polka/parse?

Hey, yes! You can install now:

npm install --save @polka/parse@next

thank you, waiting for an official release and sources to be published on github!

It is both official and available on GitHub: https://github.com/lukeed/polka/tree/next/packages/parse

It's just not marked as "stable" since I want everything to be 1.0 at the same time. However, this module hasn't changed in a long time and should be considered as stable. I'm already using it in production

ah, sorry, missed that!

Thanks a lot again!

@lukeed is there plains to mention how to parse the body of a request in the project readme? This seems likely something nearly all users would want to know about but I had to search issues to learn that this parse module exists and is recommended 😄

Hi @danawoodman, please find my answer in this thread: https://github.com/lukeed/polka/issues/95#issuecomment-492763159

You can use @polka/parse or bring body-parser if you're used to that. They should be roughly the same

Sorry @lukeed, I did see that above, I guess I was just saying maybe it could also live in the README somewhere as right now I couldn't find this answer except in this ticket 😅

When there's a site, it will be on there. As it is the readme is too long for most people to read it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ASaiAnudeep picture ASaiAnudeep  Â·  4Comments

lukeed picture lukeed  Â·  10Comments

itaditya picture itaditya  Â·  3Comments

fanatid picture fanatid  Â·  5Comments

charleslxh picture charleslxh  Â·  3Comments