Pages return HTML and Server Actions mutate data from a form. Neither helps when the caller is not a browser rendering your UI: a mobile app asking for JSON, Stripe 238 posting a webhook, a feed reader wanting XML. For those you need a plain HTTP endpoint, and the App Router spells that route.ts.
A route handler is a file whose exports are named after HTTP methods and return a Web Response — no framework request object to learn, no res.send(). Next to it sits one file that runs before routing happens at all: proxy.ts, which Next.js 16 10,514 renamed from middleware.ts. Everything written before October 2025 calls this file middleware, and so do parts of the framework's own output.

Both files run on the server only, both stay out of the client bundle, and neither works in a static export.