콘텐츠로 이동

함수: NextRequest

Source URL: https://nextjs.org/docs/app/api-reference/functions/next-request

Copy page

마지막 업데이트: 2026년 2월 20일

NextRequest는 추가 편의 메서드를 제공하기 위해 Web Request API를 확장합니다.

요청의 Set-Cookie 헤더를 읽거나 변경합니다.

이름을 전달하면 해당 값을 가진 쿠키를 요청에 설정합니다.

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

쿠키 이름을 전달하면 해당 쿠키 값을 반환합니다. 쿠키가 없으면 undefined를 반환합니다. 여러 쿠키가 있으면 첫 번째 쿠키를 반환합니다.

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

쿠키 이름을 전달하면 해당 쿠키의 모든 값을 반환합니다. 이름이 없으면 요청의 모든 쿠키를 반환합니다.

// 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 request
request.cookies.getAll()

쿠키 이름을 전달하면 요청에서 해당 쿠키를 삭제합니다.

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

쿠키 이름을 전달하면 요청에 쿠키가 존재하면 true를 반환합니다.

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

요청에서 모든 쿠키를 제거합니다.

request.cookies.clear()

Next.js 전용 속성을 포함해 네이티브 URL API를 확장하는 추가 편의 메서드를 제공합니다.

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

사용 가능한 옵션은 다음과 같습니다:

PropertyTypeDescription
basePathstringURL의 base path.
buildIdstringundefined
pathnamestringURL의 pathname입니다.
searchParamsObjectURL의 검색 매개변수입니다.

참고: Pages Router의 국제화 속성은 App Router에서 사용할 수 없습니다. App Router 국제화에 대해 더 알아보세요.

VersionChanges
v15.0.0ipgeo가 제거되었습니다.

Was this helpful?

supported.

Send