Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
Use this file to discover all available pages before exploring further.
NextResponse extends the native Web Response API with additional convenience methods for use in Middleware and Route Handlers.
Static methods
NextResponse.json()
Creates a Response with a JSON body and sets the Content-Type header to application/json.
app/api/route.ts
The value to serialize as JSON.
Optional response options:
status, statusText, headers.NextResponse.redirect()
Creates a response that redirects the user to a URL.
The destination URL.
Optional response options (e.g.
{ status: 308 } for permanent redirect).NextResponse.rewrite()
Creates a response that rewrites (proxies) the request to a given URL while keeping the original URL in the browser address bar.
The URL to proxy the request to.
NextResponse.next()
Continues to the next middleware or route handler without modifying the response. Useful in middleware when you want to pass through with optional header modifications.
cookies
Read or mutate the Set-Cookie header of the response.
Returns the first cookie with the given name.
Returns all cookies with the given name, or all cookies if no name is provided.
Sets a cookie on the response.
Returns
true if the cookie exists on the response.Deletes the cookie from the response. Returns
true if deleted.Example: middleware with auth check
middleware.ts
