NextRequest extends the native Web Request API with additional convenience methods for use in Middleware and Route Handlers.
middleware.ts
cookies
Read or mutate the cookies on the incoming request.
Returns the first cookie with the given name, or
undefined if not found.Returns all cookies with the given name, or all cookies if no name is provided.
Sets a cookie on the request.
Deletes the cookie with the given name. Returns
true if deleted, false otherwise.Returns
true if the cookie exists.Removes all cookies from the request.
nextUrl
Extends the native URL API with Next.js-specific properties.
Available properties
| Property | Type | Description |
|---|---|---|
basePath | string | The base path of the URL. |
buildId | string | undefined | The build identifier of the Next.js app. Can be customized. |
pathname | string | The URL pathname. |
searchParams | URLSearchParams | The URL search parameters. |
The internationalization properties available in the Pages Router (
locale, locales, defaultLocale, domainLocale) are not available in the App Router. Use the App Router internationalization guide instead.Inherited from Request
NextRequest inherits all properties and methods from the native Request API, including:
method— HTTP method (e.g.'GET','POST')url— The full request URL as a stringheaders— A read-onlyHeadersobjectbody— The request body as aReadableStreamjson(),text(),arrayBuffer(),formData()— Body parsing methods
Example
middleware.ts
Version history
| Version | Changes |
|---|---|
v15.0.0 | ip and geo properties removed. |
