0

Route Handlers (route.ts)

APIused in ~78% of apps

Server Actions cover your own forms, but the moment something outside your React tree needs to talk to your app — a mobile client, a Stripe webhook, a cron job, a public JSON feed — you need a real HTTP endpoint. That is what a route.ts file is, and most tutorials teach it like it is still pages/api. It is not.

Core idea. A `route.ts` file turns a folder into an HTTP endpoint. You export one async function per HTTP method (`GET`, `POST`, `PATCH`, `DELETE`, …); each receives a standard `Request` and returns a standard `Response`. It is dynamic by default in Next.js 16, and any request data you read — `cookies()`, `headers()`, `params` — is now async and must be awaited.
Playground, this isn't a screenshot
CRUD ↔ HTTP verb
POSTCreateGETReadPATCHUpdateDELETEDelete
local list (React state)2 items
#1Ship the feed
#2Review PRs
network — request / response
Add, edit, or delete an item. Watch the HTTP verb fire, then the local list update after the response.

Each mutation waits for the server's response, then updates the local list immutably (map / filter / spread) — no full refetch. Showing the change before the response is optimistic UI (#71).

↑ play a little first, then dig in