benchmarks/fastapi_reference.py
from typing import Annotated
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse
from pydantic import Field
app = FastAPI()
Int64 = Annotated[int, Field(strict=True, ge=-(2**63), le=2**63-1)]
@app.get("/health", response_class=PlainTextResponse)
async def health():
return "ok"
@app.get("/greet/{name}")
async def greeting(name: str, prefix: str = "Hello"):
return {"message": prefix + ", " + name}
@app.post("/sum")
async def sum_numbers(numbers: list[Int64]):
return (sum(numbers)+2**63) % 2**64-2**63