Skip to content

Commit 129135f

Browse files
Update read-one.md
1 parent 893f8bd commit 129135f

File tree

1 file changed

+7
-181
lines changed

1 file changed

+7
-181
lines changed

docs/tutorial/fastapi/read-one.md

Lines changed: 7 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,14 @@ We want to get the hero based on the `id`, so we will use a **path parameter** `
1212

1313
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>.
1414

15-
///
16-
17-
//// tab | Python 3.10+
18-
19-
```Python hl_lines="6"
20-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}
21-
22-
# Code here omitted 👈
23-
24-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
25-
```
26-
27-
////
28-
29-
//// tab | Python 3.9+
30-
31-
```Python hl_lines="8"
32-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}
33-
34-
# Code here omitted 👈
35-
36-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
37-
```
38-
39-
////
40-
41-
//// tab | Python 3.7+
42-
43-
```Python hl_lines="8"
44-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}
45-
46-
# Code here omitted 👈
47-
48-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
49-
```
50-
51-
////
15+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl=[6] *}
5216

5317
/// details | 👀 Full file preview
5418

55-
//// tab | Python 3.10+
56-
57-
```Python
58-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
59-
```
60-
61-
////
62-
63-
//// tab | Python 3.9+
64-
65-
```Python
66-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
67-
```
68-
69-
////
70-
71-
//// tab | Python 3.7+
72-
73-
```Python
74-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
75-
```
76-
77-
////
78-
79-
///
19+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}
8020

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

83-
```
84-
/heroes/2
85-
```
86-
8723
## Handling Errors
8824

8925
Then, because FastAPI already takes care of making sure that the `hero_id` is an actual integer, we can use it directly with `Hero.get()` to try and get one hero by that ID.
@@ -96,139 +32,29 @@ And to use it, we first import `HTTPException` from `fastapi`.
9632

9733
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.
9834

99-
//// tab | Python 3.10+
100-
101-
```Python hl_lines="1 9-11"
102-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}
103-
104-
# Code here omitted 👈
105-
106-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
107-
```
108-
109-
////
110-
111-
//// tab | Python 3.9+
112-
113-
```Python hl_lines="3 11-13"
114-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}
115-
116-
# Code here omitted 👈
117-
118-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
119-
```
120-
121-
////
35+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl[1,9:11] *}
12236

123-
//// tab | Python 3.7+
124-
125-
```Python hl_lines="3 11-13"
126-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}
127-
128-
# Code here omitted 👈
129-
130-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
131-
```
132-
133-
////
37+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[59:65] *}
13438

13539
/// details | 👀 Full file preview
13640

137-
//// tab | Python 3.10+
138-
139-
```Python
140-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
141-
```
142-
143-
////
144-
145-
//// tab | Python 3.9+
146-
147-
```Python
148-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
149-
```
150-
151-
////
152-
153-
//// tab | Python 3.7+
154-
155-
```Python
156-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
157-
```
41+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}
15842

15943
////
16044

161-
///
162-
16345
## Return the Hero
16446

16547
Then, if the hero exists, we return it.
16648

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

169-
//// tab | Python 3.10+
170-
171-
```Python hl_lines="6 12"
172-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:1-2]!}
173-
174-
# Code here omitted 👈
51+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py ln[1:2] hl[6:12] *}
17552

17653
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py[ln:59-65]!}
177-
```
178-
179-
////
180-
181-
//// tab | Python 3.9+
182-
183-
```Python hl_lines="8 14"
184-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:1-4]!}
185-
186-
# Code here omitted 👈
187-
188-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py[ln:61-67]!}
189-
```
190-
191-
////
192-
193-
//// tab | Python 3.7+
194-
195-
```Python hl_lines="8 14"
196-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:1-4]!}
197-
198-
# Code here omitted 👈
199-
200-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py[ln:61-67]!}
201-
```
202-
203-
////
20454

20555
/// details | 👀 Full file preview
20656

207-
//// tab | Python 3.10+
208-
209-
```Python
210-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py!}
211-
```
212-
213-
////
214-
215-
//// tab | Python 3.9+
216-
217-
```Python
218-
{!./docs_src/tutorial/fastapi/read_one/tutorial001_py39.py!}
219-
```
220-
221-
////
222-
223-
//// tab | Python 3.7+
224-
225-
```Python
226-
{!./docs_src/tutorial/fastapi/read_one/tutorial001.py!}
227-
```
228-
229-
////
230-
231-
///
57+
{* ./docs_src/tutorial/fastapi/read_one/tutorial001_py310.py *}
23258

23359
## Check the Docs UI
23460

0 commit comments

Comments
 (0)