All quizzesMedium
API Routes & Middleware — Series 2
Preview — 3 of 10 questions
How do you handle multiple HTTP methods on the same route in app/api/users/route.ts?
AExport a single default function that switches on request.method
BCreate separate files per method: route.get.ts, route.post.ts
CExport one named async function per HTTP verb — GET, POST, PUT, DELETE, … — each receiving the request
DExport a methods array listing the allowed verbs
Which statement about cookies in middleware.ts is correct?
AMiddleware can only read cookies, never set them
BMiddleware runs in the Node.js runtime by default, so any Node cookie library works
CMiddleware runs on the Edge runtime by default; it reads with request.cookies.get() and writes by calling response.cookies.set() on the NextResponse it returns
DCookies set in middleware are never sent to the browser
When must you use generateMetadata instead of a static export const metadata?
ANever — generateMetadata is deprecated
BOnly in the root layout.tsx
COnly in the Pages Router
DWhen the metadata depends on dynamic data — route params, searchParams, or an async fetch (e.g. a post's title from a CMS)
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.