next/server module provides Web-standard request/response wrappers and middleware utilities that work across runtimes (Node.js, Cloudflare Workers, Deno).
Import
NextRequest
Extends the standardRequest with Next.js-specific conveniences.
Constructor
URL | RequestInfo
required
URL string, URL object, or Request object.
RequestInit
Standard Request options (method, headers, body, etc.).
Properties
NextURL
Enhanced URL object with pathname helpers.
RequestCookies
Read-only cookie accessor.
string | undefined
Client IP address (from trusted headers).Priority:
CF-Connecting-IP(Cloudflare)X-Real-IPX-Forwarded-For(first entry)
GeoData | undefined
Geolocation data (platform-dependent).Available fields:
country?: string— ISO country codecity?: stringregion?: string— State/provincelatitude?: stringlongitude?: string
Usage Example
NextResponse
Extends the standardResponse with Next.js middleware helpers.
Constructor
Static Methods
<T>(body: T, init?: ResponseInit) => NextResponse<T>
Create a JSON response.
(url: string | URL, status?: number) => NextResponse
Create a redirect response.
(destination: string | URL, init?) => NextResponse
Rewrite to a different URL (proxy pattern).The client sees the original URL; the server fetches from the destination.
(init?: MiddlewareResponseInit) => NextResponse
Continue to the next handler.
Properties
ResponseCookies
Cookie setter for responses.Methods:
set(name, value, options?)— Set a cookiedelete(name)— Delete a cookie (sets Max-Age=0)get(name)— Read a cookie (from Set-Cookie headers)getAll()— Read all cookies
Usage Examples
NextURL
Lightweight URL wrapper with pathname helpers.Properties
string
Full URL string.
string
Protocol + hostname + port (e.g.,
https://example.com:3000).string
URL path (e.g.,
/api/users).string
Query string with
? prefix (e.g., ?page=1).URLSearchParams
URLSearchParams instance for reading/writing query params.
string
Hash fragment with
# prefix (e.g., #section-2).Methods
() => NextURL
Create a copy of the URL.
() => string
Convert to string (same as
.href).NextFetchEvent
Middleware event object (provideswaitUntil for background work).
(promise: Promise<any>) => void
Register a promise to keep the runtime alive after the response is sent.Useful for:
- Logging
- Analytics
- Cache warming
Utility Functions
userAgent
Parse User-Agent header.boolean
Whether the user agent is a known bot/crawler.
{ name?: string; version?: string; major?: string }
Browser information.
{ model?: string; type?: string; vendor?: string }
Device information.
{ name?: string; version?: string }
Operating system information.
after
Schedule work after the response is sent (Next.js 15+).connection
Signal that the response requires a live connection (opt out of ISR).Cache-Control: no-store and bypasses ISR caching.
Cookie Options
Middleware Type
null, undefined, or void is equivalent to NextResponse.next().
Runtime Compatibility
All APIs use Web-standard primitives and work across:- Node.js (18+)
- Cloudflare Workers
- Deno
- Vercel Edge Runtime
- Any WinterCG-compatible runtime
Source
View source code → Implementation:/home/daytona/workspace/source/packages/vinext/src/shims/server.ts