So, we're basically trying to accomplish a progress bar for a particular task on the server. So, our

So, we're basically trying to accomplish a progress bar for a particular task on the server. So, our team decided to stream the response and process each chunk separately... So in the client we do something like this:
const res = await fetch(`/api/something`, { method: "POST" });

const stream = res.body?.getReader();

while (true) {
    if (!stream) {
        // break
    }

    const { done, value } = await stream.read();

    if (!value) break;

    updateProgress(value);

    if (done) break;
}
Was this page helpful?