📝 Add note about path declaration order

This commit is contained in:
Sebastián Ramírez
2019-02-16 19:23:42 +04:00
parent 80b68cd97d
commit a809da5567
3 changed files with 27 additions and 6 deletions

View File

@@ -98,6 +98,24 @@ You can use the same type declarations with `str`, `float`, `bool` and many othe
These are explored in the next chapters of the tutorial.
## Order matters
When creating *path operations*, you can find situations where you have a fixed path.
Like `/users/me`, let's say that it's to get data about the current user.
And then you can also have a path `/users/{user_id}` to get data about a specific user by some user ID.
Because path operations are evaluated in order, you need to make sure that the path for `/users/me` is declared before the one for `/users/{user_id}`:
```Python hl_lines="6 11"
{!./src/path_params/tutorial003.py!}
```
Otherwise, the path for `/users/{user_id}` would match also for `/users/me`, "thinking" that it's receiving a parameter `user_id` with a value of `"me"`.
## Recap
With **FastAPI**, by using short, intuitive and standard Python type declarations, you get: