CodePark/ questions / Route handlers & middleware
START PRACTICINGPRACTICE
Frontend question · Next.js › Route handlers & middleware

How do you create a GET /api/users endpoint in the App Router?

app/api/users/route.ts exporting async function GET(request: Request)

app/api/users/route.ts exporting async function GET(request: Request) is correct. Route Handlers live in a route.ts file and export functions named after HTTP methods, such as GET and POST. The tempting app/api/users/index.ts with a default export is wrong: default-exported handlers belong to the Pages Router's pages/api folder.