AI Workshop: learn to build apps with AI →
Fetch: The Request object

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


The Request object represents a resource request, and it’s usually created using the new Request() API.

Example:

const req = new Request('/api/todos')

The Request object offers several read-only properties to inspect the resource request details, including:

  • method: the request’s method (GET, POST, etc.)
  • url: the URL of the request.
  • headers: the associated Headers object of the request
  • referrer: the referrer of the request
  • cache: the cache mode of the request (e.g., default, reload, no-cache).

It also exposes methods such as json(), text(), and formData() to read the body of the request.

The full API can be found at https://developer.mozilla.org/docs/Web/API/Request

Lessons in this unit:

0: Introduction
1: How to use Fetch
2: Catching errors in network requests
3: The Response object
4: Getting the body content
5: ▶︎ The Request object
6: Request headers
7: POST requests