Question presented to candidate: "You are moving /pages/api endpoints to the App Router. What are Route Handlers, how is the code different, and what do you need to watch for?"
What a strong answer should cover:
- A Route Handler is a
route.tsfile inapp/that exports functions named after HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS). - It uses the Web standard
RequestandResponse(plusNextRequestandNextResponsehelpers), not Node-stylereqandres. - Unexported methods return 405 automatically; dynamic segments arrive as an awaited
paramsPromise in the second argument. - GET handlers are dynamic by default since Next.js 15; without Cache Components you opt into static output with
export const dynamic = 'force-static'. With Cache Components (the create-next-app default in 16.4) that export is a build error: a GET is prerendered when it reads no request or uncached data, and'use cache'caches the rest. - Pages API routes still work side by side; there is one default-exported
handler(req, res)per file with a method switch.
Clarifying questions expected:
- "Do any endpoints rely on Node-specific res methods or body parser config?" β they need rewriting.
- "Should any GET endpoint be static?" β it now needs an explicit opt-in.
Code / implementation expected: Yes β the same endpoint in both styles.