Accessing the ReadableStream
What you'll learn: How to use the response.body property to get direct access to the underlying stream from a fetch response.
Why Access the Raw Stream?
When you call response.json() or response.text(), you're using convenient wrapper methods. But underneath, the response data arrives as a ReadableStream. Sometimes you need direct access to this stream—for real-time processing, progress tracking, or handling data chunk-by-chunk as it arrives.
The response.body Property
Every Response object exposes a body property that gives you the raw ReadableStream:
const response = await fetch('https://example.com/large-file.json');
// Access the underlying stream
const stream = response.body;
That's it! response.body returns the ReadableStream directly. This is the same stream that methods like json() and text() consume internally—except now you control how to read it.
When to Use This
You access response.body when you need:
- Progress tracking: Read chunks as they arrive and update a progress bar
- Streaming processing: Handle massive files without loading everything into memory
- Custom parsing: Process data incrementally before it's fully downloaded
Think of it like opening a water tap. The convenience methods (json(), text()) give you a full bucket at the end. But response.body gives you the actual flowing stream—you decide how to collect or use the water as it flows.
Important Note
Once you access response.body, the stream is yours to manage. You can't call response.json() afterward—the stream can only be consumed once.
Key Takeaway: Use response.body to access the raw ReadableStream from a fetch response when you need direct control over how data is read and processed as it arrives.