FastAPI - @app.get variables

by
Jeremy Canfield |
Updated: November 25 2024
| FastAPI articles
In this example, id is an integer.
from fastapi import FastAPI
app = FastAPI()
@app.get("/api/{id}")
async def foo(id: int):
return {"id": id}
In this example, bar is a string.
from fastapi import FastAPI
app = FastAPI()
@app.get("/api/{bar}")
async def foo(bar: str | ):
return {"bar": bar}
Did you find this article helpful?
If so, consider buying me a coffee over at