What are Route Handlers and how do they differ from API Routes?
Assesses fundamental understanding of Next.js conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
Route Handlers live in app/api/.../route.ts and export HTTP-method functions such as GET, POST, PUT, DELETE and PATCH. They receive a standard Request and return a Response or NextResponse, support streaming, and can be cached or made dynamic with route segment config. They can run on the Node or Edge runtime via export const runtime = 'edge'.
export async function GET() {
const data = await db.query();
return Response.json(data);
}
API Routes live in pages/api/*.ts, export a single default handler using (req, res) with helpers like res.status().json(), and are the older Pages Router model. Route Handlers are the App Router equivalent and are recommended for new projects.
Both run only on the server, so secrets stay safe. Prefer Server Actions for form-driven mutations and use route handlers for public APIs, webhooks and third-party callbacks.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.