Trying to create this FastAPI app using three optional path paarameters. I tried expanding the code into three optional inputs shown below, it now forces me to input all three; otherwise, a 404 'detail not found' error is raised.
import json
from datetime import date
from typing import Optional
@app.get("/order/{country}/{menu}/{dt}")
async def ppp(country: Optional[str] = None, menu: Optional[str] = None, dt: Optional[date] = None):
a = {}
if country is not None:
a["a"] = country
else:
return "nothing inside"
if menu is not None:
a["b"] = menu
else:
return a
if dt is not None:
a["c"] = dt
return a
Expected result:
url input: http://127.0.0.1:8000/order/usa/vegan/2023-01-01
correct output: {"a":"usa","b":"vegan","c":"2023-01-01"}
However:
(1/3)
url input: http://127.0.0.1:8000/order/usa/vegan/
output: {"detail":"Not Found"}
expected output: {"a":"usa","b":"vegan"}
(2/3)
url input: http://127.0.0.1:8000/order/usa/
output: {"detail":"Not Found"}
expected output: {"a":"usa"}
(3/3)
url input: http://127.0.0.1:8000/order/
output: {"detail":"Not Found"}
expected output: "nothing inside"
All three errors shown '404 Not Found' in my uvicorn terminal