Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 13 / Topic 1 of 6

The route.ts convention, confirmed against this install's own docs

The installed route-handlers.md guide states the convention plainly: "Route Handlers are defined in a route.js|ts file inside the app directory... Route Handlers can be nested anywhere inside the app directory, similar to page.js and layout.js. But there cannot be a route.js file at the same route segment level as page.js." This part adds four real route files to this harness, none of them colliding with an existing page:

harness/app/api/status/[pnr]/route.ts         — GET
harness/app/api/status/[pnr]/delay/route.ts   — POST
harness/app/api/ops/ping/route.ts             — GET (static, section 6)
harness/app/api/ops/now/route.ts              — GET (dynamic, section 6)

app/status/[pnr]/page.tsx (Parts 8–9) and app/api/status/[pnr]/route.ts (this part) are different route segments — one starts with /status, the other with /api/status — so both coexist; next build confirms it by listing both in the route table with no conflict error. The supported methods are exactly the installed guide's list: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS — anything else, or a method the file simply doesn't export, gets a 405 automatically (section 5).

Done here? The practice set for Part 13 — including the solutions — is on the part page.

Search the guide