Skip to main content

Response Types

Route handlers and middleware return Response objects. BurgerAPI uses the standard Web API Response.

Common patterns

JSON response:

return Response.json({ message: "Hello" });
return Response.json({ error: "Not found" }, { status: 404 });

Plain text or HTML:

return new Response("OK", { status: 200 });
return new Response("<h1>Hello</h1>", {
headers: { "Content-Type": "text/html" },
});

Custom headers:

return new Response(body, {
status: 200,
headers: { "X-Custom": "value" },
});

Middleware can return a Response to stop the chain, or undefined to continue, or a function that receives the handler’s response and returns a new Response (e.g. for CORS). See Middleware Return Types and After Middleware.