Building an API endpoint directly inside the App Router, using a route.ts file.
A route.ts (or .js) file inside the App Router defines a Route Handler — the App Router's replacement for the Pages Router's API routes. It exports functions named after HTTP methods (GET, POST, PUT, DELETE) that receive a standard Web Request and return a standard Web Response, rather than the Next-specific req/res objects the Pages Router used.
A route segment can be a page or a Route Handler, but not both — page.tsx and route.ts can't coexist in the same folder. GET Route Handlers are cached by default unless they read dynamic request data or explicitly opt out, and — like any other route — a Route Handler can run on either the Node or Edge runtime depending on what it actually needs to do.
What you'll walk away knowing