Could you please explain to me why in FastAPI the following works:
@app.post("/items/v1/cards{sku}")
async def create_item(sku: str):
return {"status":200,"sku":sku} # returns status:200 and sku
but, the same endpoint with questionmark in it like the one given below does not?
@app.post("/items/v1/cards?{sku}")
async def create_item(sku: str):
return {"sku":sku} # returns 404
In the first code snippet, you defined the parameter as a Path parameter and worked as expected.
URL Example:
In the second one, however, you attempted to pass a Query parameter in the wrong way. As per the documentation:
Hence, your endpoint should look like this:
URL Example: