Functions
NextResponse
NextResponse adds convenience methods for JSON, redirects and response cookies. Use ordinary Response when framework helpers are unnecessary. Set cookies on the response actually returned; do not assume an incoming-cookie edit persists in the browser. Source: https://nextjs.org/docs/app/api-reference/functions/next-response. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.
Formal Syntax & Structure
nextjs syntaxnextjs
import { NextResponse } from "next/server";Working Example
Example Snippetnextjs
import {NextResponse} from 'next/server';export function POST(){const response=NextResponse.json({view:'compact'});response.cookies.set('view','compact',{path:'/',sameSite:'lax',secure:true});return response;}