-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfastapi_parameters_query.py
More file actions
51 lines (36 loc) · 1.1 KB
/
fastapi_parameters_query.py
File metadata and controls
51 lines (36 loc) · 1.1 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
fake_items_db = [
{"item_name": "foo"},
{"item_name": "bar"},
{"item_name": "baz"},
]
@app.get("/items/")
async def read_items(skip: int = 0, limit: int = 10):
return fake_items_db[skip : skip + limit]
@app.get("/items/{item_id}")
async def read_item(
item_id: str, needy: str, q: Optional[str] = None, short: bool = False
):
item = {"item_id": item_id, "needy": needy}
if q:
item.update({"q": q})
if not short:
item.update(
{"description": "that is an amazing item that has long description"}
)
return item
@app.get("/users/{user_id}/items/{item_id}")
async def read_user_item(
user_id: int, item_id: str, q: Optional[str] = None, short: bool = False
):
item = {"item_id": item_id, "owner_id": user_id}
if q:
item.update({"q": q})
if not short:
item.update(
{"description": "that is an amazing item that has long description"}
)
return item
# PYTHONPATH=module_fastapi uvicorn fastapi_parameters_query:app --reload