You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial/fastapi/read-one.md
+7-181Lines changed: 7 additions & 181 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,78 +12,14 @@ We want to get the hero based on the `id`, so we will use a **path parameter** `
12
12
13
13
If you need to refresh how *path parameters* work, including their data validation, check the <ahref="https://fastapi.tiangolo.com/tutorial/path-params/"class="external-link"target="_blank">FastAPI docs about Path Parameters</a>.
For example, to get the hero with ID `2` we would send a `GET` request to:
82
22
83
-
```
84
-
/heroes/2
85
-
```
86
-
87
23
## Handling Errors
88
24
89
25
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`.
96
32
97
33
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.
0 commit comments