from fastapi import FastAPI, Request
import json
import trio
import hypercorn.trio
from hypercorn.config import Config
app = FastAPI()
@app.post("/test")
async def test(request: Request):
    body = await request.body()
    try:
        return {"result": json.loads(body)}
    except Exception as e:
        return {"error": str(type(e).__name__) + ": " + str(e), "body_repr": repr(body)}

config = Config()
config.bind = ["127.0.0.1:8000"]
trio.run(hypercorn.trio.serve, app, config)
