Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Important
Security Advisory: React2Shell & two new vulnerabilities
Find out more

NextRequest

Last updated June 16, 2025

NextRequest extends theWeb Request API with additional convenience methods.

cookies

Read or mutate theSet-Cookie header of the request.

set(name, value)

Given a name, set a cookie with the given value on the request.

// Given incoming request /home// Set a cookie to hide the banner// request will have a `Set-Cookie:show-banner=false;path=/home` headerrequest.cookies.set('show-banner','false')

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.

// Given incoming request /home// { name: 'show-banner', value: 'false', Path: '/home' }request.cookies.get('show-banner')

getAll()

Given a cookie name, return the values of the cookie. If no name is given, return all cookies on the request.

// Given incoming request /home// [//   { name: 'experiments', value: 'new-pricing-page', Path: '/home' },//   { name: 'experiments', value: 'winter-launch', Path: '/home' },// ]request.cookies.getAll('experiments')// Alternatively, get all cookies for the requestrequest.cookies.getAll()

delete(name)

Given a cookie name, delete the cookie from the request.

// Returns true for deleted, false is nothing is deletedrequest.cookies.delete('experiments')

has(name)

Given a cookie name, returntrue if the cookie exists on the request.

// Returns true if cookie exists, false if it does notrequest.cookies.has('experiments')

clear()

Remove all cookies from the request.

request.cookies.clear()

nextUrl

Extends the nativeURL API with additional convenience methods, including Next.js specific properties.

// Given a request to /home, pathname is /homerequest.nextUrl.pathname// Given a request to /home?name=lee, searchParams is { 'name': 'lee' }request.nextUrl.searchParams

The following options are available:

PropertyTypeDescription
basePathstringThebase path of the URL.
buildIdstring |undefinedThe build identifier of the Next.js application. Can becustomized.
pathnamestringThe pathname of the URL.
searchParamsObjectThe search parameters of the URL.

Note: The internationalization properties from the Pages Router are not available for usage in the App Router. Learn more aboutinternationalization with the App Router.

Version History

VersionChanges
v15.0.0ip andgeo removed.

Was this helpful?

supported.

[8]ページ先頭

©2009-2025 Movatter.jp