Fetch API

The standard JavaScript function fetch() for making HTTP requests, built into browsers and current server runtimes, which returns a promise for the response.

In more detail

const res = await fetch(url, options) gives a Response with status, headers and methods such as res.json(). Options include method, headers, body and signal. It only rejects on network failure; HTTP error statuses such as 404 still resolve, so check res.ok.

Examples

await fetch(url, { next: { revalidate: 3600, tags: ['products'] } });
Starting a fetch is a side effect, so in React it belongs in an event handler, an Effect or a data library, never directly in rendering.

Related terms

Taught in

References