Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
220 changes: 6 additions & 214 deletions docs/en/docs/tutorial/body-multiple-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,9 @@ First, of course, you can mix `Path`, `Query` and request body parameter declara

And you can also declare body parameters as optional, by setting the default to `None`:

//// tab | Python 3.10+
{* ../../docs_src/body_multiple_params/tutorial001_an_py310.py hl[18:20] *}

```Python hl_lines="18-20"
{!> ../../docs_src/body_multiple_params/tutorial001_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="18-20"
{!> ../../docs_src/body_multiple_params/tutorial001_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="19-21"
{!> ../../docs_src/body_multiple_params/tutorial001_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="17-19"
{!> ../../docs_src/body_multiple_params/tutorial001_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="19-21"
{!> ../../docs_src/body_multiple_params/tutorial001.py!}
```

////
## Multiple body parameters

/// note

Expand All @@ -81,21 +33,8 @@ In the previous example, the *path operations* would expect a JSON body with the

But you can also declare multiple body parameters, e.g. `item` and `user`:

//// tab | Python 3.10+

```Python hl_lines="20"
{!> ../../docs_src/body_multiple_params/tutorial002_py310.py!}
```

////
{* ../../docs_src/body_multiple_params/tutorial002_py310.py hl[20] *}

//// tab | Python 3.8+

```Python hl_lines="22"
{!> ../../docs_src/body_multiple_params/tutorial002.py!}
```

////

In this case, **FastAPI** will notice that there is more than one body parameter in the function (there are two parameters that are Pydantic models).

Expand Down Expand Up @@ -136,57 +75,8 @@ If you declare it as is, because it is a singular value, **FastAPI** will assume

But you can instruct **FastAPI** to treat it as another body key using `Body`:

//// tab | Python 3.10+

```Python hl_lines="23"
{!> ../../docs_src/body_multiple_params/tutorial003_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="23"
{!> ../../docs_src/body_multiple_params/tutorial003_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="24"
{!> ../../docs_src/body_multiple_params/tutorial003_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///
{* ../../docs_src/body_multiple_params/tutorial003_an_py310.py hl[23] *}

```Python hl_lines="20"
{!> ../../docs_src/body_multiple_params/tutorial003_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="22"
{!> ../../docs_src/body_multiple_params/tutorial003.py!}
```

////

In this case, **FastAPI** will expect a body like:

Expand Down Expand Up @@ -226,57 +116,8 @@ q: str | None = None

For example:

//// tab | Python 3.10+

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="29"
{!> ../../docs_src/body_multiple_params/tutorial004_an.py!}
```

////
{* ../../docs_src/body_multiple_params/tutorial004_an_py310.py hl[28] *}

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="26"
{!> ../../docs_src/body_multiple_params/tutorial004_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="28"
{!> ../../docs_src/body_multiple_params/tutorial004.py!}
```

////

/// info

Expand All @@ -298,57 +139,8 @@ item: Item = Body(embed=True)

as in:

//// tab | Python 3.10+

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005_an_py310.py!}
```

////

//// tab | Python 3.9+

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005_an_py39.py!}
```

////

//// tab | Python 3.8+

```Python hl_lines="18"
{!> ../../docs_src/body_multiple_params/tutorial005_an.py!}
```

////

//// tab | Python 3.10+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="15"
{!> ../../docs_src/body_multiple_params/tutorial005_py310.py!}
```

////

//// tab | Python 3.8+ non-Annotated

/// tip

Prefer to use the `Annotated` version if possible.

///

```Python hl_lines="17"
{!> ../../docs_src/body_multiple_params/tutorial005.py!}
```
{* ../../docs_src/body_multiple_params/tutorial005_an_py310.py hl[17] *}

////

In this case **FastAPI** will expect a body like:

Expand Down