NextRequest
NextRequest extends the Web Request API with additional convenience methods.
cookies
Read or mutate the Set-Cookie
header of the request.
set(name, value)
Given a name, set a cookie with the given value on the request.
get(name)
Given a cookie name, return the value of the cookie. If the cookie is not found, undefined
is returned. If multiple cookies are found, the first one is returned.
getAll()
Given a cookie name, return the values of the cookie. If no name is given, return all cookies on the request.
delete(name)
Given a cookie name, delete the cookie from the request.
has(name)
Given a cookie name, return true
if the cookie exists on the request.
clear()
Remove the Set-Cookie
header from the request.
nextUrl
Extends the native URL
API with additional convenience methods, including Next.js specific properties.
The following options are available:
Property | Type | Description |
---|---|---|
basePath | string | The base path of the URL. |
buildId | string | undefined | The build identifier of the Next.js application. Can be customized. |
pathname | string | The pathname of the URL. |
searchParams | Object | The search parameters of the URL. |
Note: The internationalization properties from the Pages Router are not available for usage in the App Router. Learn more about internationalization with the App Router.
ip
The ip
property is a string that contains the IP address of the request. This value can optionally be provided by your hosting platform.
Good to know: On Vercel, this value is provided by default. On other platforms, you can use the
X-Forwarded-For
header to provide the IP address.
geo
The geo
property is an object that contains the geographic information of the request. This value can optionally be provided by your hosting platform.
Good to know: On Vercel, this value is provided by default. On other platforms, you can use the
X-Forwarded-For
header to provide the IP address, then use a third-party service to lookup the geographic information.