Next.js Discord

Discord Forum

Is there any downside to always using NextRequest/NextResponse instead of Request/Response?

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
With NextRequest and NextResponse:
export async function POST(request: NextRequest): Promise<NextResponse> {
  const headers = request.headers;

  return NextResponse.json(headers);
}

With plain Request and Response:
export async function POST(request: Request): Promise<Response> {
  const headers = request.headers;

  return new Response(JSON.stringify(headers));
}

Given the Next types are a superset of the plain Req/Res, it could reduce some mental overhead if you could just blanket use them everywhere even when you're not using the extra utilities. Does this create bloat in output module size, slow down requests, have certain DX consequences, etc though?
Answered by joulev
No, there isn’t any consequences significant enough to note
View full answer

2 Replies