Skip to content

Non-JSON and raw responses

View as Markdown

Use c.otherResponse() for the supported native text types: text/csv and text/plain.

responses: {
200: c.otherResponse({ contentType: "text/csv", body: z.string() }),
}

The handler can return the ordinary typed shape:

return {
status: 200,
body: "task_id,title,status\n1,Audit launch checklist,completed\n",
};

Return a raw Response only for streaming, a download filename, or custom headers the normal return cannot express. It bypasses both the handler’s declared response type and runtime response-shape enforcement. The contract may still document the intended output, but focused tests must prove the raw status, headers, body, and cancellation behavior.