interface FormBody
Since 0.5.0

A parsed form body: the read-only view IRequest.formData?() resolves and parseFormBody returns.

Named FormBody, never FormData, so it cannot shadow the global. The web standard's semantics are adopted; the write side (set/append/delete) is not — a request body is a fact about the request, not a collection a handler edits.

Examples

Example 1

const form = await ctx.request.formData();
const token = form.get('_csrf');
if (typeof token !== 'string' || token === '') {
  // No usable token — the value was a file or absent.
}

Methods

get(name: string): FormValue | undefined

Returns the FIRST value for a name, or undefined when the name is absent — the web standard's get, with undefined (narrowable) in place of null.

getAll(name: string): readonly FormValue[]

Returns every value for a name in wire order — the web standard's getAll, so a repeated field (multi-select, multi-file) keeps the order the client sent.

The returned array is the parse's own READ view, not a defensive copy: mutating it mutates what later getAll calls return. Treat it as read-only (the IResponse.snapshot() precedent — a copy would allocate on every read of a value most readers never touch).

entries(): IterableIterator<[string, FormValue]>

Iterates every [name, value] pair in wire order — the enumeration primitive for reading a form whose field names the reader does not know ahead of time (the hand-rolled new URLSearchParams(body) iteration this accessor replaces).

Usage

import { type FormBody } from "common/src/index.ts";