Routing: Route Handlers | Next.js
Route Handlers allow you to create custom request handlers for a given route using the Web Request and Response APIs. Good to know: Route Handlers are only available inside the app directory. They are the equivalent of API Routes inside the pages directory meaning you do not need to use API Routes and Route Handlers together. Route Handlers are defined in a route.js|ts file inside the app directory: Route Handlers can be nested inside the app directory, similar to page.js and layout.js. But there cannot be a route.js file at the same route segment level as page.js. The following HTTP methods are supported: GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS. If an unsupported method is called, Next.js will return a 405 Method Not Allowed response. In addition to supporting native Request and Response . Next.js extends them with NextRequest and NextResponse to provide convenient helpers for advanced use cases. Route Handlers are cached by default when using the GET method with the Resp
This page is also available as Markdown at /docs/app/api-reference/file-conventions/route.md . For an index of Next.js documentation , see /docs/llms.txt . Copy page route.js Last updated March 3, 2026 Route Handlers allow you to create custom request handlers for a given route using the Web Request and Response APIs. route.ts TypeScript JavaScript TypeScript export async function GET () { return Response .json ({ message : 'Hello World' }) } Reference HTTP Methods A route file allows you to create custom request handlers for a given route. The following HTTP methods are supported: GET , POST
Explore this link on the map →related reading
- Cursor Docs — Agent, Rules, MCP, Skills & CLIdocs.cursor.com
- Getting Started: Layouts and Pages | Next.jsnextjs.org
- Getting Started: Error Handling | Next.jsnextjs.org
- Town | The AI Assistant That Does the Worktown.com
- projects, claire wangclairebookworm.com
- Documentation | NestJS - A progressive Node.js frameworkdocs.nestjs.com
- Getting Started: Layouts and Pages | Next.jsnextjs.org
- Building a single-page application with Next.js and React Routercolinhacks.com
- Getting Started: Caching | Next.jsnextjs.org
- The Content Operating System for the AI era | Sanitysanity.io
- LessWronglesswrong.com
- Routing · Express.jsexpressjs.com