CORE CONCEPTS

Request Utilities

ctx.request (and its alias ctx.req) is a standard Web API Request. Futon ships a small set of standalone helper functions for the common things you'd otherwise write by hand: URL parsing and body parsing.

URL Helpers

URL helpers
import { getPathname, getQueryParams, getQueryParam } from '@rasenganjs/futon'; app.get('/debug', async (ctx) => { const pathname = getPathname(ctx.request); // "/debug" const allParams = getQueryParams(ctx.request); // { page: "2", ... } const page = getQueryParam(ctx.request, 'page'); // "2" | null return json({ pathname, allParams, page }); });

Body Parsing

The Request body is a ReadableStream. It can only be read once. Futon's body parsers are plain async functions you call directly, or via the bodyParser() middleware for automatic parsing.

Manual body parsing
import { parseJson, parseUrlEncoded, parseFormData, parseText, parseBody, } from '@rasenganjs/futon'; app.post('/api/data', async (ctx) => { const data = await parseJson(ctx.request); return json({ received: data }); });
FunctionParsesReturns
parseJson(request)application/jsonParsed JSON value
parseUrlEncoded(request)application/x-www-form-urlencodedRecord<string, string>
parseFormData(request)multipart/form-dataNative FormData
parseText(request)AnyRaw string
parseBody(request)Auto-detects via Content-TypeOne of the above

parseBody() inspects the Content-Type header and dispatches to the right parser. This is exactly what the bodyParser() middleware uses internally.

Multipart Form Data

For file uploads specifically, reach for fileUpload() instead of calling parseFormData() yourself. It handles field/file separation, size limits, and storage engines.

Query Parameters
Response Helpers