Why does litestar need to manually register the route handlers #4105
Unanswered
duohelingdukele
asked this question in
Q&A
Replies: 1 comment
|
There is a difference here; In the FastAPI version, you need access to the Litestar's approach encourages decoupling and modularisation. For example, it's very easy to re-use route handler objects: @get("/")
async def some_handler() -> None:
...
v1_router = Router("/v1", [some_handler])
v2_router = Router("/v2", [some_handler])It also enables a truly stateless and modular approach: # app/some_module.py
@get("/")
async def some_handler() -> None:
...
def create_some_router(base_path: str, guards: list[Guard]) -> Router:
return Router(base_path, [some_handler], guards=guards)
# app/app.py
def create_app(debug: bool) -> Litestar:
some_guards = []
if debug:
some_guards.append(require_authenticated)
return Litestar([create_some_router("/v1", guards=some_guards),])I wouldn't say that you need to manually register things in Litestar, I'd say that Litestar allows you to be more flexible and explicit. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Litestar requires manually passing in a handler list parameter. But other frameworks automatically register handlers when decorators declare routing paths.
All reactions