-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfastapi_data_types.py
More file actions
32 lines (26 loc) · 939 Bytes
/
fastapi_data_types.py
File metadata and controls
32 lines (26 loc) · 939 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
import uuid
from datetime import datetime, time, timedelta
from typing import Optional
from uuid import UUID
from fastapi import FastAPI, Body, Path
app = FastAPI()
@app.put("/items/{item_id}")
async def read_items(
item_id: UUID = Path(..., example=uuid.uuid4()),
start_datetime: Optional[datetime] = Body(None),
end_datetime: Optional[datetime] = Body(None),
repeat_at: Optional[time] = Body(None),
process_after: Optional[timedelta] = Body(None, example=timedelta(hours=1)),
):
start_process = start_datetime + process_after
duration = end_datetime - start_process
return {
"item_id": item_id,
"start_datetime": start_datetime,
"end_datetime": end_datetime,
"repeat_at": repeat_at,
"process_after": process_after,
"start_process": start_process,
"duration": duration,
}
# PYTHONPATH=module_fastapi uvicorn fastapi_data_types:app --reload