0Pricing
JavaScript Academy · Lesson

Streaming fetch Responses

Process large responses as they arrive.

Responses Are Streams

A fetch Response exposes its body as a ReadableStream via response.body. Instead of awaiting the full payload, you can process bytes as they arrive.

const res = await fetch("/big-file");
const stream = res.body; // ReadableStream of Uint8Array

Reading the Body Stream

response.body yields Uint8Array chunks. Get a reader and loop just like any readable stream.

const reader = res.body.getReader();
while (true) {
  const { value, done } = await reader.read();
  if (done) break;
  console.log("received", value.length, "bytes");
}

All lessons in this course

  1. Readable Streams
  2. Streaming fetch Responses
  3. Transform Streams
  4. Backpressure and Piping
← Back to JavaScript Academy