Fastapi: Endpoint with parameter that has forward "/" slashes

Created on 21 Jul 2020  路  3Comments  路  Source: tiangolo/fastapi

Is there a way to put a parameter that is part of the URL but it has forward-slashes?

For example:

from fastapi import FastAPI

app = FastAPI()


@app.get("/items/{path}")
def read_root(path:str="/inventory/armor/helmet):
    return path

With that route above, if I put example.com/items/this/is/my/path I get a 404.

question

All 3 comments

thanks for the reply; I've put the {path} as a query string parameter now.

@app.get("/items")
def read_root(k:str =Query(None)):
    return path

This works and seems safe.

Thanks for the help here @Kludex! :clap: :bow:

Thanks for reporting back and closing the issue @NickDatLe :+1:

Was this page helpful?
0 / 5 - 0 ratings