Skip to main content

Body

Declare a request body parameter for a path operation. Body parameters are sent as JSON in the request body.

Signature

Parameters

Any
default:"Undefined"
Default value if the parameter field is not set.
bool | None
default:"None"
When embed is True, the parameter will be expected in a JSON body as a key instead of being the JSON body itself. This happens automatically when more than one Body parameter is declared.
str
default:"application/json"
The media type of this parameter field. Changing it would affect the generated OpenAPI, but currently it doesn’t affect the parsing of the data.
str | None
default:"None"
An alternative name for the parameter field. This will be used to extract the data and for the generated OpenAPI.
str | None
default:"None"
Human-readable title for the parameter.
str | None
default:"None"
Human-readable description for the parameter.
float | None
default:"None"
Greater than validation. If set, the value must be greater than this. Only applicable to numbers.
float | None
default:"None"
Greater than or equal validation. If set, the value must be greater than or equal to this. Only applicable to numbers.
float | None
default:"None"
Less than validation. If set, the value must be less than this. Only applicable to numbers.
float | None
default:"None"
Less than or equal validation. If set, the value must be less than or equal to this. Only applicable to numbers.
int | None
default:"None"
Minimum length for strings.
int | None
default:"None"
Maximum length for strings.
str | None
default:"None"
RegEx pattern for strings.
str | None
default:"None"
Parameter field name for discriminating the type in a tagged union.
bool | None
default:"None"
If True, strict validation is applied to the field.
float | None
default:"None"
Value must be a multiple of this. Only applicable to numbers.
bool | None
default:"None"
Allow inf, -inf, nan. Only applicable to numbers.
int | None
default:"None"
Maximum number of allowed digits for numbers.
int | None
default:"None"
Maximum number of decimal places allowed for numbers.
list[Any] | None
default:"None"
Example values for this field.
bool | str | None
default:"None"
Mark this parameter field as deprecated. It will affect the generated OpenAPI (visible at /docs).
bool
default:"True"
Whether to include this parameter field in the generated OpenAPI.
dict[str, Any] | None
default:"None"
Any additional JSON schema data.

Examples

Single Body Parameter

Request body:

Embed Single Body Parameter

Request body:
Use embed=True when you want a single value to be expected as a key in the JSON body instead of being the body itself.

Multiple Body Parameters

Request body:

Mixing Body with Other Parameters

Request body:

Singular Values in Body

Body with Validations

When using Body() with singular values (not Pydantic models), remember to use embed=True if you want the value to be wrapped in a JSON object with a key.