Skip to content

Instantly share code, notes, and snippets.

@ericness
Created July 26, 2023 12:34
Show Gist options
  • Save ericness/306f2aff8897ee7502a04f89fb9cd6a9 to your computer and use it in GitHub Desktop.
Save ericness/306f2aff8897ee7502a04f89fb9cd6a9 to your computer and use it in GitHub Desktop.
FastAPI to sum a list of numbers.
app = FastAPI()
class Numbers(BaseModel):
numbers: List[float]
@app.post("/sum/")
async def sum_payload(nums: Numbers) -> JSONResponse:
"""Sum a list of numbers."""
result = sum(nums.numbers)
return JSONResponse(content={"sum": result})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment