I have defined a route in Starlette/FastApi -
@router.post("/{part}")
def post_method(part):
return "ok"
@router.post("/{part}/{another_part}")
def another_post_method(part, another_part):
return "ok"
I have some forward slash in the path components, and I want to make the following request to access post_method
curl -X POST "http://127.0.0.1:5000/api/path%2Fpath" -H "accept: application/json" -d ""
results in the 404 error in the Starlette/Fastapi logs.
INFO: 127.0.0.1:50233 - "POST /api/path/path HTTP/1.1" 404
How to get the correct path components?
You can use Starlette built-in path convertor
@app.route("/path/{param:path}", name="path-convertor")
Response from Marcelo Trylesinski (Kludex) in fastapi gitter:
This issue has also been raised on FastApi Github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With