Request limits and bodies
Global and per-route body size caps, streaming bodies, and when Flare buffers versus streams.
Flare enforces body size limits and chooses buffering versus streaming based on your contract descriptor. Oversized bodies return 413 ContentTooLarge. Malformed JSON returns 400.
Global default
Section titled “Global default”The global cap is host.maxBodyBytes in flare.json (default 2 MiB). See flare.json reference.
{ "host": { "maxBodyBytes": 2097152 }}Override at runtime: FLARE__HOST__MAXBODYBYTES=4194304.
Per-route override
Section titled “Per-route override”Add maxBodyBytes on the route descriptor (inline field or httpContract entry):
import { httpContract } from "@flare-ts/core";import { model, str } from "@flare-ts/lib/schema";
class FeedbackBody extends model({ message: str.min(1) }) {}
const FeedbackContract = httpContract({ submit: { body: FeedbackBody, maxBodyBytes: 51200, },});Bodies over the limit return 413 with { error: "ContentTooLarge", code: 413, detail: { maxBytes } }.
JSON bodies
Section titled “JSON bodies”When the descriptor declares a body schema or model(), Flare buffers and validates JSON after before middleware. Read the result from scope.input.body (inline) or ctx.extract(entry).body (controller). An empty or missing JSON body becomes null.
Streaming bodies
Section titled “Streaming bodies”Declare body: stream (import stream from @flare-ts/core) to skip JSON buffering. The inbound stream attaches before before middleware runs.
import { FlareHost, FlareResponse, stream } from "@flare-ts/core";import { node } from "@flare-ts/core/node";
const host = new FlareHost(node);
host.http.post("/upload", { body: stream, maxBodyBytes: 50 * 1024 * 1024 }, async (ctx) => { let bytes = 0; for await (const chunk of ctx.req.stream()) { bytes += chunk.byteLength; } return new FlareResponse(200, { bytes });});
const app = host.build();app.run();Size is enforced while iterating chunks, not only up front.
One read strategy per request. stream() throws if buffer(), text(), or json() already started.
Manual body readers
Section titled “Manual body readers”Without a body in the descriptor, Flare does not parse JSON. Use ctx.req.buffer(), text(), json(), or stream() directly. See Requests.
Validation failures
Section titled “Validation failures”| Input | Status | Body shape |
|---|---|---|
| Route params | 400 | Invalid route parameters message |
| Query string | 400 | Invalid query parameters message |
| JSON body (schema failure) | 400 | { error, details: [ field errors ] } |
| Body too large | 413 | ContentTooLarge with maxBytes |
These bypass host.http.error().