-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple.py
More file actions
31 lines (26 loc) · 835 Bytes
/
multiple.py
File metadata and controls
31 lines (26 loc) · 835 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
from fastapi import FastAPI, Query, Path
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from typing import Annotated
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str | None = None
username: str
password: str
age: int | None = 19
@app.put("/{id}", tags=["update data"])
async def read_root(id: Annotated[int, Path(title="product id", ge=0, le=100)], query: Annotated[str | None, Query(title="search query")] = None, item: Item | None = None):
print(id)
print(query)
print(item)
result = {"user_id": id}
if query:
result.update({
"query":query
})
if item:
result.update({
"item": jsonable_encoder(item)
})
return JSONResponse(content=result, status_code=200)