File size: 888 Bytes
91a6497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4097c0
91a6497
 
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
from fastapi import FastAPI
from typing import List, Union
from pydantic import BaseModel
from fastapi import FastAPI, HTTPException,BackgroundTasks
import random
import asyncio

class CoordinatesPayload(BaseModel):
    coords: Union[str, List[List[float]]]
    state: str
    duration: int
    delay : int

app = FastAPI()

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.post("/send-coordinates")
async def receive_coordinates(payload: CoordinatesPayload,background_tasks: BackgroundTasks):
    coords= payload.coords
    state_= payload.state
    duration= payload.duration
    delay= payload.delay
    print ( f"Hi from client ,you send coords :{coords} ,state {state_} , duration :{duration} ,delay : {delay}")
    await asyncio.sleep(3)
    return {"Answer": f"Hi from server ,you send coords :{coords} ,state {state_} , duration :{duration} ,delay : {delay}"}