API routes
The Pages Router way of writing back-end endpoints: files in pages/api that export a handler taking req and res.
In more detail
They still work in the Pages Router. App Router projects use Route Handlers, which are built on Web standard Request and Response instead of Node.js objects.
Related terms
- Route Handlers — Files in a Next.js app, named route.ts, that answer HTTP requests for a path with functions named after methods such as GET and POST.
- Pages Router — The original Next.js router, where files in pages/ became routes and data was loaded with special functions.
- req and res — The request and response objects that Node.js-style handlers receive, conventionally named req and res.
Taught in
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Route Handlers: RESTful Endpoints with NextRequest — Next.js 15 & Modern App Router Architecture
- Runtime Environments: Node.js vs Edge Runtime Choice — Next.js 15 & Modern App Router Architecture