Skip to content
Closed
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
186 changes: 9 additions & 177 deletions docs/tutorial/fastapi/read-one.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,13 @@ We want to get the hero based on the `id`, so we will use a **path parameter** `

If you need to refresh how *path parameters* work, including their data validation, check the <a href="https://fastapi.tiangolo.com/tutorial/path-params/" class="external-link" target="_blank">FastAPI docs about Path Parameters</a>.

///
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl[6] *}

//// tab | Python 3.10+

```Python hl_lines="6"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
```

////

//// tab | Python 3.9+

```Python hl_lines="8"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
```

////

//// tab | Python 3.7+

```Python hl_lines="8"
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
```

////
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[59:65] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
```

////

///
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}

For example, to get the hero with ID `2` we would send a `GET` request to:

Expand All @@ -96,139 +38,29 @@ And to use it, we first import `HTTPException` from `fastapi`.

This will let the client know that they probably made a mistake on their side and requested a hero that doesn't exist in the database.

//// tab | Python 3.10+

```Python hl_lines="1 9-11"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl[1,9:11] *}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
```

////

//// tab | Python 3.9+

```Python hl_lines="3 11-13"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
```

////

//// tab | Python 3.7+

```Python hl_lines="3 11-13"
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
```

////
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[59:65] hl[1,9:11] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
```
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
```

////

///

## Return the Hero

Then, if the hero exists, we return it.

And because we are using the `response_model` with `HeroPublic`, it will be validated, documented, etc.

//// tab | Python 3.10+

```Python hl_lines="6 12"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
```

////

//// tab | Python 3.9+

```Python hl_lines="8 14"
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}

# Code here omitted 👈
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl[6:12] *}

{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
```

////

//// tab | Python 3.7+

```Python hl_lines="8 14"
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
```

////
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[59:65] hl[6:12] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
```

////

///
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}

## Check the Docs UI

Expand Down
Loading