API REFERENCE
Response
import { ResponseBuilder } from '@rasenganjs/futon'; import { json, text, html, redirect, status, notFound, streamResponse, nodeStreamToResponse, setCookie, clearCookie, serializeCookie, } from '@rasenganjs/futon'; import type { CookieOptions } from '@rasenganjs/futon';
Every function here returns a standard Web API Response, so the pipeline stays platform-agnostic. See Response Helpers for usage.
ResponseBuilder
class ResponseBuilder { statusCode: number; // 200 by default status(code: number): this; header(name: string, value: string): this; removeHeader(name: string): this; json(data: unknown, init?: ResponseInit): Response; send(text: string, init?: ResponseInit): Response; html(text: string, init?: ResponseInit): Response; redirect(url: string, status?: number): Response; stream(stream: ReadableStream<Uint8Array>, init?: ResponseInit): Response; nodeStream( nodeStream: { pipe: (destination: WritableStream<Uint8Array>) => void }, init?: ResponseInit ): Response; }
Available as ctx.response / ctx.res, created lazily on first access. status(), header(), and removeHeader() are chainable and mutate the builder in place; every other method finalizes and returns a Response (further calls to status()/header() after that are no-ops).
app.get('/api', async (ctx) => { return ctx.res .status(201) .header('X-Created', 'true') .json({ created: true }); }); app.get('/old-page', async (ctx) => { return ctx.res.redirect('/new-page', 301); });
Standalone Factories
function json(data: unknown, init?: ResponseInit): Response; function text(value: string, init?: ResponseInit): Response; function html(value: string, init?: ResponseInit): Response; function redirect(url: string, status?: number): Response; function status(code: number, body?: string): Response; function notFound(body?: string): Response; function streamResponse( stream: ReadableStream<Uint8Array>, init?: ResponseInit ): Response; function nodeStreamToResponse( nodeStream: { pipe: (destination: WritableStream<Uint8Array>) => void }, init?: ResponseInit ): Response;
These are the same primitives ctx.res is built on — reach for them when you don't have a Context (e.g. constructing a response ahead of time, or in code outside a handler).
Cookies
function setCookie( response: Response, name: string, value: string, options?: CookieOptions ): Response; function clearCookie( response: Response, name: string, options?: CookieOptions ): Response; function serializeCookie( name: string, value: string, options?: CookieOptions ): string;
interface CookieOptions { domain?: string; path?: string; // default "/" maxAge?: number; // seconds; omitted = session cookie httpOnly?: boolean; secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'; expires?: Date; }
setCookie() returns a new Response with a Set-Cookie header appended (the original response's status, body, and headers are preserved). clearCookie() is setCookie() with maxAge: 0. serializeCookie() produces just the header value string, for cases where you're building headers manually.
const res = json({ ok: true }); return setCookie(res, 'session', token, { httpOnly: true, secure: true, maxAge: 86400, });
