papi/papi/main.py

44 lines
726 B
Python

from typing import Optional
from pydantic import BaseModel
from fastapi import FastAPI, Request, Body
from collections import defaultdict
app = FastAPI()
mesures = defaultdict(list)
class Sonde(BaseModel):
identifiant: str
nom: str
sondes = {"test": Sonde(identifiant="test", nom="Testlocal")}
@app.get("/")
def read_root():
return {"msg": "Hello World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
@app.post("/sonde/")
def post_sonde(sonde: Sonde):
print(sonde)
sondes[sonde.identifiant] = sonde
return list(sondes.values())
@app.get("/sonde/")
def list_sonde():
return [x for x in sondes.values()]