Bootstrap FreeKB - FastAPI - @app.get variables
FastAPI - @app.get variables

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 67e035 in the box below so that we can be sure you are a human.