Was told Litestar is intended to route differently based on the type of the path parameter:
Q: Is Litestar intended to route differently based on the type of the path parameter
A: ... this only works if the parameters you pass in are actually compatible and distinct, e.g. using a str is basically a catch-all, so if you provide that last, it will always match
However, when providing route handlers in the order of int path param handler
followed by str path param handler
, the str path param handler
is the only one that is called in the example code below.
No response
from litestar import Litestar, get
@get("/{id:int}")
async def hello_world_int(id: int) -> str:
return f"Hello, world (int)! {id}"
@get("/{id:str}")
async def hello_world_str(id: str) -> str:
return f"Hello, world (str)! {id}"
# Expect that path "/42" would route to hello_world_int
# and path "/abc" would go to hello_world_str
app = Litestar([hello_world_int, hello_world_str])
1. Run app: `litestar run`
2. In browser access: 127.0.0.1:8000/42
3. Result: Hello, world (str)! 42
Error: (expected to see "(int)" rather than "(str)"
4. In browser access: 127.0.0.1:8000/ABC
5. Result (as expected): Hello, world (str)! ABC
No response
No response
2.9.1
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too