export async function GET(request) { return new Response(JSON.stringify({ message: 'Hello GET' }), { status: 200, headers: { 'Content-Type': 'application/json' } }); }
The GET handler returns a JSON string with the message key. The response content type is application/json, so the client receives the JSON string.
Option B correctly defines an async POST function that reads JSON from the request and returns a Response object with status 201.
Option B uses lowercase 'post' which Next.js does not recognize.
Option B lacks the request parameter needed to read data.
Option B returns a string instead of a Response object, which is invalid.
export async function POST(request) { const body = await request.json(); if (!body.name) { return new Response('Missing name', { status: 400 }); } return new Response('Created', { status: 201 }); }
If the request JSON has a 'name' property, the handler returns status 201. Otherwise, it returns 400.
Option C lacks the request parameter but tries to use it, causing a ReferenceError at runtime.
Other options correctly accept request and use it properly.
Response objects let you control HTTP status codes and headers like content type. Returning just a string limits control over the response.