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.

In more detail

They are Next.js's way of building API endpoints next to the pages. Their request bodies come from outside and need validating like any other input.

Example

export async function GET() {
  return Response.json({ status: 'ok', time: new Date().toISOString() });
}

Related terms

Taught in

References