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

Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions docs/en/docs/tutorial/path-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ Because *path operations* are evaluated in order, you need to make sure that the

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"`.

Similarly, you cannot redefine a path operation:

```Python hl_lines="6 11"
{!../../../docs_src/path_params/tutorial003b.py!}
```

The first one will always be used since the path matches first.

## Predefined values

If you have a *path operation* that receives a *path parameter*, but you want the possible valid *path parameter* values to be predefined, you can use a standard Python <abbr title="Enumeration">`Enum`</abbr>.
Expand Down
13 changes: 13 additions & 0 deletions docs_src/path_params/tutorial003b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import FastAPI

app = FastAPI()


@app.get("/users")
async def read_users():
return ["Rick", "Morty"]


@app.get("/users")
async def read_users2():
return ["Bean", "Elfo"]