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
- Request and Response objects — The objects the Fetch API uses to represent an HTTP request and its response, including URL, method, headers and body.
- ReadableStream — A browser object that delivers data in chunks as it arrives, such as a fetch response.body, instead of all at once at the end.
- AbortController — The standard JavaScript object for cancelling asynchronous work: its signal is handed to the work, and calling abort() cancels it.
- fetch keepalive — A fetch option, keepalive: true, that lets a small request keep going after the page that started it has been closed or navigated away.
- HTTP — The protocol web browsers and web servers use to send requests and responses.
- code generation — Producing client or server code automatically from a machine-readable contract such as an OpenAPI document or a Protocol Buffers file.
- TanStack Query — A library that fetches, caches and refreshes server data in frontend apps, and runs changes to it as mutations.
- Data Cache — The second Next.js caching tier: a server-side store of fetch results that persists across requests, users and deployments.
- Request Memoization — The first Next.js caching tier: identical fetch calls made while rendering one request are run only once.
- cache tag — A label attached to cached data, such as products, so all entries with that label can be invalidated together.
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- fetch-on-render — A data loading approach where each component starts its request only after it has rendered, usually in an Effect.
Taught in
- Cancellation With AbortController And Async Signal Propagation — Frontend Architecture & Web Platform
- Same-Origin Policy, CORS Preflight, Credentials And Headers — Frontend Architecture & Web Platform
- The Fetch API: Streaming Responses, HTTP Caching And Keepalive — Frontend Architecture & Web Platform
- Type-Safe Client Generation: Orval & Automated SDKs — Production Full-Stack Engineering
- Server Components: Async Execution & Constraints — Next.js 15 & Modern App Router Architecture
- Granular Suspense: Resolving Waterfall Bottlenecks — Next.js 15 & Modern App Router Architecture
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Server Actions: use server Directives & Mutations — Next.js 15 & Modern App Router Architecture
- Request Memoization: Automatic Deduplication Tiers — Next.js 15 & Modern App Router Architecture
- Data Cache: Cross-Request Persistence & Fetch Tags — Next.js 15 & Modern App Router Architecture
- Native HTTP Server: Request & Response Lifecycles — Node.js Internals & Backend Services
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services
- Production Hardening: Graceful Shutdown & Docker — Node.js Internals & Backend Services
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- useTransition: Non-Blocking State Updates for Fluid UI — React 19 & Modern Component Architecture
- Code-Splitting with React.lazy: Dynamic Imports And Chunks — React 19 & Modern Component Architecture
- React Portals: Escaping Stacking Contexts for Modals — React 19 & Modern Component Architecture
- Client-Side Data Fetching Architectures with Suspense — React 19 & Modern Component Architecture