Skip to content

Configuration

The plugin accepts an options object configuring four content-type families. Each entry can be a config object (enabled with overrides), true (enabled with defaults), or false (disabled).

typescript
router.use(body({
    json: { limit: '1mb', strict: true },
    urlEncoded: { limit: '100kb' },
    raw: { limit: '5mb' },
    text: false,
}));
OptionDefaultDefault content-types
jsontrueapplication/json
urlEncodedtrueapplication/x-www-form-urlencoded
rawfalse(opt-in for readRequestBodyBytes, readRequestBodyArrayBuffer, readRequestBodyBlob)
textfalse(opt-in for readRequestBodyText)

json

Parses application/json requests.

PropertyTypeDefaultDescription
limitnumber | stringnoneMaximum size — bytes or '1mb' style
strictbooleantrueOnly accept arrays and objects (rejects bare values)
reviverfunctionForwarded to JSON.parse
typestring | string[]'application/json'Content-types this parser claims
typescript
router.use(body({
    json: { limit: '1mb', strict: true },
}));

urlEncoded

Parses application/x-www-form-urlencoded requests.

PropertyTypeDefaultDescription
limitnumber | stringnoneMaximum body size
parameterLimitnumber1000Maximum number of fields
typestring | string[]'application/x-www-form-urlencoded'Content-types this parser claims

raw

Configures the raw-byte readers. Off by default — opt in if you call readRequestBodyBytes, readRequestBodyArrayBuffer, or readRequestBodyBlob.

PropertyTypeDefaultDescription
limitnumber | stringnoneMaximum body size

text

Configures the text reader.

PropertyTypeDefaultDescription
limitnumber | stringnoneMaximum body size
defaultCharsetstring'utf-8'Used when no charset is in the Content-Type header
typestring | string[]'text/plain'Content-types this parser claims

Released under the MIT License.