-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
38 lines (29 loc) · 1.02 KB
/
main.py
File metadata and controls
38 lines (29 loc) · 1.02 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
from typing import Annotated
from fastapi import FastAPI, Path, Query
from fastapi.responses import JSONResponse
app = FastAPI()
@app.get("/products/{product_id}", tags=["Get single product"])
def getProduct(product_id: int):
print(product_id)
return {"hello"}
@app.get("/products/{product_id}", tags=["Get single product"])
def getProduct(product_id: int):
print(product_id)
return {"hello"}
@app.get("/users/{id}", tags=["get single user"])
async def getUser(id: Annotated[int, Path(title="user id")]):
print(id)
result = {
"id": 1
}
if id:
result.update({"path": id})
return JSONResponse(content=result, status_code=200)
@app.get("/posts/{id}", tags=["get single post"])
async def get_post(id: Annotated[int, Path(title="post id", ge=0, le=20)], query: Annotated[str | None, Query(alias="your_name")] = None):
result = {
"id": 1
}
if id and query:
result.update({"post_id": id, "query": query})
return JSONResponse(content=result, status_code=200)