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

Request Body Methods

Using .text(), .json(), .formData(), .blob(), and .arrayBuffer() to consume request bodies.

Request Body Methods

You'll learn how to read and consume the body data from a Request object using five built-in methods.

What Are Request Body Methods?

When you create or receive a Request object, its body contains raw data that needs to be interpreted in a useful format. Just like receiving a package that you need to open and unpack, you need to choose the right method to extract the contents. JavaScript provides five specialized methods to read request bodies depending on what format you expect the data to be in.

The Five Body Methods

Each method is asynchronous (returns a Promise) and can only be called once per request:

  • .text() – Reads the body as plain text (a string)
  • .json() – Parses the body as JSON and returns a JavaScript object
  • .formData() – Parses the body as form data (returns a FormData object)
  • .blob() – Reads the body as binary data (returns a Blob object)
  • .arrayBuffer() – Reads the body as raw binary data (returns an ArrayBuffer)

Choosing the Right Method

Think of these methods as different "unpacking tools." If you're expecting JSON data, use .json(). If you're handling file uploads or binary content, use .blob() or .arrayBuffer(). Plain text? Use .text().

const request = new Request('/api/data', {
  method: 'POST',
  body: JSON.stringify({ name: 'Alex' })
});

// Read the request body as JSON
const data = await request.json();
// data is now { name: 'Alex' }

Important: You can only read a body once. After calling any body method, the request's body is consumed and cannot be read again.

Key Takeaway: Request body methods (.text(), .json(), .formData(), .blob(), .arrayBuffer()) let you extract and parse request body data in different formats, but each request body can only be read once.