Created
July 26, 2023 12:34
-
-
Save ericness/306f2aff8897ee7502a04f89fb9cd6a9 to your computer and use it in GitHub Desktop.
FastAPI to sum a list of numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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