Files
FastAPI_async/api/testAPI.py
2025-09-25 10:40:29 +02:00

34 lines
935 B
Python

from fastapi import (
APIRouter,
status,
Body, Depends)
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
from influx_related import get_influxdb_client, get_influx_data, write_influx_data
router = APIRouter()
@router.get(
path="/get_influx/",
name='get data from influxdb, last one hour',
#response_model=InfluxDBClientAsync,
responses={
status.HTTP_401_UNAUTHORIZED: {},
}
)
async def get_influx(client: InfluxDBClientAsync = Depends(get_influxdb_client)):
return {'results': await get_influx_data(client)}
@router.post(
path="/write_influx/",
name='write data to influxdb',
#response_model=InfluxDBClientAsync,
responses={
status.HTTP_401_UNAUTHORIZED: {},
}
)
async def write_influx(temp: float, client: InfluxDBClientAsync = Depends(get_influxdb_client)):
await write_influx_data(client, temp)
return {"status": "OK"}