-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.py
More file actions
33 lines (27 loc) · 779 Bytes
/
path.py
File metadata and controls
33 lines (27 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi import FastAPI, Path, Query
from typing import Annotated
app = FastAPI()
"""
@app.get("/{id}")
def get(id: Annotated[int, Path(title="The ID of the item")]):
# Path params if is alawys required
print(type(id))
results = {"id": id}
return results
@app.get("/{id}")
def get(id: Annotated[int, Path(title="The ID of the item")],
q: Annotated[str | None, Query(alias="query")] = None):
print(type(id))
results = {"id": id}
if q:
results.update({"q": q})
return results
"""
@app.get("/item/{item_id}")
async def item_id(item_id: Annotated[int, Path(title="10", ge=0, le=20)], q: str):
if item_id and q:
return {
"item_id": item_id,
"query": q
}
return {"dont": 'have'}