Skip to main content
Route Handlers let you create custom HTTP endpoints for a route using the Web Request and Response APIs.
route.ts

HTTP methods

The following HTTP methods are supported: GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
route.ts
If OPTIONS is not defined, Next.js automatically implements it and sets the Allow response header based on the other defined methods.

Parameters

NextRequest
A NextRequest object, which extends the Web Request API with convenience methods for cookies and a parsed nextUrl object.
route.ts
object
An optional second parameter containing route context.context.params — a promise that resolves to the dynamic route parameters for the current route.
app/dashboard/[team]/route.ts

TypeScript helper

Use the global RouteContext helper for strongly typed route params:
app/users/[id]/route.ts
Types are generated during next dev, next build, or next typegen. RouteContext is globally available and does not need to be imported.

Examples

Reading and setting cookies

route.ts

Reading request headers

route.ts

Reading the request body

app/items/route.ts

Reading form data

app/items/route.ts

URL query parameters

app/api/search/route.ts

Dynamic route segments

app/items/[slug]/route.ts

Redirects

app/api/route.ts

Streaming responses

app/api/route.ts

CORS headers

app/api/route.ts

Webhooks

app/api/webhook/route.ts

Non-UI responses

app/rss.xml/route.ts

Revalidating cached data

app/posts/route.ts

Version history