NextResponse

Next.js' extension of the Web Response object, with helpers for JSON responses, cookies, redirects and rewrites.

In more detail

NextResponse.json(data) builds a JSON response. In middleware, NextResponse.next() continues to the route, NextResponse.redirect() sends the browser elsewhere and NextResponse.rewrite() serves another path under the same URL.

Example

return NextResponse.json({ status: 'ok' }, { status: 200 });

Related terms

Taught in

References