File Conventions

Route Handler convention

Route handlers use named method exports in app route files. A page and handler cannot own the same segment. In the Cache Components-disabled lane, GET handlers are uncached by default; opt into compatible caching explicitly. If OPTIONS is omitted, the framework supplies it. Do not equate method dispatch with authorization. Source: https://nextjs.org/docs/app/api-reference/file-conventions/route. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.

Formal Syntax & Structure

nextjs syntaxnextjs
export function GET(request: Request) { /* response */ }

Working Example

Example Snippetnextjs
// app/api/books/route.tsexport function GET() {  return Response.json({ items: [{ id: 'moss', title: 'Moss Atlas' }] });}
Next.js Reference