Loading
A built-in browser function for making HTTP requests — like asking a server for data.
A modern alternative to XMLHttpRequest. `fetch(url)` returns a Promise resolving to a Response. Call `.json()` to parse JSON (also a Promise). Check `response.ok` before using the body — fetch only rejects on network failure, not 4xx/5xx status codes.
Extended by Next.js to add caching semantics (`cache`, `next.revalidate`). Supports streaming responses via `response.body` (a ReadableStream). Can be cancelled with AbortController/AbortSignal. In Node.js 18+, fetch is available globally without a polyfill.
const res = await fetch('/api/data');
if (!res.ok) throw new Error(res.statusText);
const data = await res.json();