Is there any downside to always using NextRequest/NextResponse instead of Request/Response?
Answered
American black bear posted this in #help-forum
American black bearOP
With
With plain
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?
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?
2 Replies
American black bearOP
That's great news. Thanks a bunch!