简体   繁体   中英

Get partially response from node js api

I want to get a response from node.js API to client-side on every step the API completes till API completes its full step.

Suppose I call localhost/api/doStepCompleate on my backend(Node.js) API will complete multiple steps but want to send every step response to the client-side till the API completes its full task.

Thank you

If this is an http request/response, then you can use res.write() on the server to send partial responses and finally call res.end() when you're done.

A challenge here will be that many clients are not set up to process partial responses. Libraries such as fetch() will wait for the entire response and not notify their caller of partial responses unless you configure the response as a stream and you have client-side code to parse arbitrary chunks of data as it arrives. See here for some idea how that can work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM