How do you read headers and search params in a Route Handler?
Tests fluency with the Web Standard Request API in Next.js App Router. A strong answer uses request.headers.get() for headers and request.nextUrl.searchParams for query params, avoiding Express-style req.query or req.headers.authorization.
WHAT THIS TESTS: This question evaluates whether you understand that Next.js App Router Route Handlers are built on Web Standard APIs rather than Node.js or Express conventions. The interviewer wants to see that you know how to extract metadata from the incoming Request object, specifically using the Headers API for request headers and the URL API for search parameters, and that you can distinguish between server-side Route Handler patterns and client-side hook patterns.
A GOOD ANSWER COVERS: First, state that a Route Handler receives a Request object, or more specifically a NextRequest instance, as its first argument. Second, for headers such as Authorization, demonstrate request.headers.get('authorization') and note that the Headers API is case-insensitive so the casing does not matter. Third, for URL search parameters, show request.nextUrl.searchParams.get('key') and explain that NextRequest provides a nextUrl property containing a pre-parsed URL object, though you could also use new URL(request.url).searchParams as a fallback. Fourth, explicitly contrast this with Express-style patterns like req.headers.authorization or req.query to show you understand the paradigm shift in the App Router. Fifth, mention that dynamic route segments are accessed via the second params argument, not the request object, to demonstrate broader Route Handler fluency.
COMMON WRONG ANSWERS: Using Express idioms like req.query for search params or req.headers['authorization'] for headers. Attempting to import useSearchParams from next/navigation, which is a client hook and unavailable in a server Route Handler. Treating headers() from next/headers as the primary or only way to read headers, when that helper is designed for Server Components and async server contexts; in Route Handlers the request object is the idiomatic source. Failing to mention that the Headers API uses get() rather than direct property access, which signals unfamiliarity with the Web Standard Request model.
LIKELY FOLLOW-UPS: How does NextRequest differ from the standard Web Request object? How would you read dynamic route segments in the same file? How do you return JSON or handle CORS preflight requests in a Route Handler? What is the difference between Route Handlers and API Routes in the Pages Router?
ONE CONCRETE EXAMPLE: In an app/api/items/route.js file, an export async function GET(request) handler reads a bearer token via const auth = request.headers.get('authorization') and filters a database query by category using const category = request.nextUrl.searchParams.get('category'). The handler returns Response.json({ items }) using the standard Web Response API.
Read the original → nextjs.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.