Course contentsShow
← Web Development
Lesson 856 of 2,98215. Browser NetworkingFree lesson

Response Body Methods

Consuming response bodies with .text(), .json(), .formData(), .blob(), and .arrayBuffer().

Response Body Methods

You'll learn how to extract and parse data from a Fetch API Response using five key methods.

When you receive a Response object from a fetch request, the actual data (the body) isn't immediately available as usable JavaScript. You need to call specific methods to consume and transform the response body into the format you need.

The Five Response Body Methods

Think of a Response like a sealed envelope — you know it contains something, but you need to open it in the right way depending on what's inside:

.text() — Reads the body as plain text. Use this for HTML, CSV, or any text-based content.

.json() — Parses the body as JSON and returns a JavaScript object. Perfect for API responses that return JSON data.

.formData() — Parses the body as form data (multipart or URL-encoded). Useful when handling form submissions from servers.

.blob() — Returns the body as a binary large object (Blob). Ideal for images, videos, PDFs, or any file download.

.arrayBuffer() — Returns raw binary data as an ArrayBuffer. Use this for low-level binary processing or working with typed arrays.

Important Notes

Each method returns a Promise, so you'll use .then() or await to get the actual data. You can only call one of these methods once per response — once consumed, the body stream is locked and cannot be read again.

// Already learned: basic fetch and response
fetch('/api/user')
  .then(response => response.json())  // Consume as JSON
  .then(data => console.log(data));

Key Takeaway: Response body methods transform the raw response stream into usable formats — choose .text(), .json(), .formData(), .blob(), or .arrayBuffer() based on the content type you're receiving.