Skip to content

Overview

Handler return types, FlareResponse, headers, cookies, streaming, and contract response serializers.

AI generated, pending review Updated 10 days ago · Flare 0.3

This section covers what Flare sends back: permitted handler return types, how values become bytes, and response-shaping features on FlareHttpContext.

TopicPage
Return types and FlareResponseThis page (below)
CookiesCookies
Signed cookiesSigned cookies
Streaming bodiesStreaming bodies
Server-sent eventsServer-sent events

For reading the inbound request, see Requests.

Handlers may return:

ReturnClient outcome
FlareResponseYour status, headers, and body
Web ResponsePass-through for fetch interop
Plain object or arrayWrapped as 200 JSON
AsyncIterable200 chunked stream
null / undefinedThrows (handler bug)
Returned Error instanceRe-thrown; use throw to reach error handlers

A plain object return is always 200. For other statuses, return FlareResponse, a controller helper (this.notFound(body)), or set status explicitly.

import { FlareHost, FlareResponse } from "@flare-ts/core";
import { node } from "@flare-ts/core/node";
const host = new FlareHost(node);
host.http.get("/me", () => {
const res = new FlareResponse(200, { id: "u1" });
res.headers["cache-control"] = "no-store";
return res;
});
const app = host.build();
app.run();
FieldMeaning
statusHTTP status code
headersOutbound headers (ResponseHeaders record)
bodyMaterialized body after serialization
jsonBodyJSON held before per-status serializer runs
bodyStreamChunked body for streaming responses

Cookies are not on FlareResponse. Set them with ctx.cookies (see Cookies).

ControllerBase exposes protected helpers (ok, created, noContent, redirect, badRequest, unauthorized, forbidden, notFound, tooManyRequests, error) that wrap new FlareResponse(...). MiddlewareBase exposes only the failure subset (badRequest, unauthorized, forbidden, notFound, tooManyRequests, error). See Controller classes.

When a descriptor declares response: { 200: schema(...) }, Flare strips properties not in the schema for matching status codes on the compiled fast path. Record and discriminated-union schemas serialize via a JSON.stringify fallback and do not filter; see Serialization and HTTP contracts.

This is the guard the unshaped path lacks: when the wire format is simply whatever the handler returned, adding a field to a shared domain object silently adds it to every response built from that object, and nothing sits between the return statement and the client to notice. Declaring the response pins the wire shape in the descriptor, so on the compiled path a field added to the model later stays off the wire until it is also declared.