Mutations, APIs and the request layer · senior
Route Handlers vs Server Actions vs a separate backend
Route Handlers (route.ts) are HTTP endpoints built on Web Request/Response, for webhooks, public or mobile APIs, files and streams; Server Actions are for mutations from your own UI; keep shared business logic in a server module both can call.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
export async function GET(request) {}inapp/.../route.ts; methods GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS; unsupported methods get 405. Aroute.tscannot share a segment withpage.tsx.- Caching: not cached by default. Previous model:
export const dynamic = "force-static"caches a GET. With Cache Components, GET handlers follow the prerender model: static if they touch no runtime/uncached data;"use cache"must go in a helper function, not the handler body. - Use Route Handlers for: webhooks (verify signatures), mobile/third-party clients, OAuth callbacks, file downloads, streaming (SSE for AI chat), custom headers and CORS.
- Use Server Actions for form submissions and button mutations from your own React UI (typed, colocated, integrated with revalidation).
- BFF pattern: Next.js aggregates microservices and shapes data for the UI; watch latency, auth propagation and ownership.
- Treat Route Handlers as public endpoints: authenticate and authorise every request (DAL
verifySession()); return 401 vs 403 correctly. - Type the context with
RouteContext<"/users/[id]">;paramsis a promise. - Do not fetch your own Route Handler from a Server Component; call the server function directly.
The red pen
Common traps: mistake → fix
Mistake: "Use Server Actions for all reads in client components"
Fix: reads belong to Server Components or GET handlers.
Mistake: "GET handlers are cached by default"
Fix: not since Next 15.
Mistake: "Duplicate the business logic in the action and the handler"
Fix: put it in one shared server module.
Easy to hard
Questions interviewers ask, easy to hard
- When would you use a Route Handler instead of a Server Action?
- Should our Next.js app be the BFF for our Node microservices?
- Our React Native app needs the same API. What do you build?
- How do you cache a GET handler in Next 16?
- How do you stream an AI response?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.