#Path parameter including slashes

1 messages · Page 1 of 1 (latest)

hollow bison
#

I want to handle all paths under a prefix, say /fixed/, with the same handler, e.g.

/fixed/
/fixed/foo
/fixed/foo/1
/fixed/bar/2
...

Path parameters capture a single path path component, is there a way to change this behavior (e.g. with a regexp)? Something like

@get("/fixed/{dynamic_path:.*}")
def handler(dynamic_path: str) -> None:
    # do something with dynamic_path
    ...
fallow palmBOT
#
Notes for Path parameter including slashes
At your assistance

@hollow bison

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.

tranquil yarrow
#

does capturing as path not work?

#
@get("/fixed/{dynamic_path:path}")
def handler(dynamic_path: Path) -> None:
    # do something with dynamic_path
    ...
hollow bison
#

Huh I'd swear i tried this and didn't work but it does now, thanks!

One minor issue is that it doesn't handle the empty string i.e. the path /fixed/ but it doesn't matter in my case.

tranquil yarrow
hollow bison
#

Still 404 (same with default=None)