Skip to content

Commit

Permalink
refactor(routing)!: Refactor routes and route handlers (#3386)
Browse files Browse the repository at this point in the history
* remove handler names
* Remove option handler creation from HTTPRoute
* Remove methods attribute from BaseRoute
* Move kwargs model to handlers and creation to on_registration
* Store kwargs model on handlers instead of routes
* Simplify HTTPRoute route_handler_map creation
* Simplify Router.route_handler_method_map
* Relax typing of HTTPRoute
* Move handling logic to route handlers
* Remove scope_type
* Don't pass route to HTTPRouteHandler during handling
* Don't pass scope to handle methods
* Resolve and establish connections in routes; Only pass connections to handlers

---------

Co-authored-by: Jacob Coffee <[email protected]>
Co-authored-by: Peter Schutt <[email protected]>
  • Loading branch information
3 people committed Jan 11, 2025
1 parent 76363ed commit 7365d41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions litestar/handlers/http_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ def on_registration(self, app: Litestar, route: BaseRoute) -> None:

self._get_kwargs_model_for_route(route.path_parameters)

def _get_kwargs_model_for_route(self, path_parameters: Iterable[str]) -> KwargsModel:
key = tuple(path_parameters)
if (model := self._kwargs_models.get(key)) is None:
model = self._kwargs_models[key] = self._create_kwargs_model(path_parameters)
return model

self._get_kwargs_model_for_route(route.path_parameters)

def _get_kwargs_model_for_route(self, path_parameters: Iterable[str]) -> KwargsModel:
key = tuple(path_parameters)
if (model := self._kwargs_models.get(key)) is None:
Expand Down
1 change: 1 addition & 0 deletions litestar/handlers/websocket_handlers/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from litestar.connection import WebSocket
from litestar.exceptions import ImproperlyConfiguredException
from litestar.handlers import BaseRouteHandler
from litestar.types import Empty
from litestar.types import AsyncAnyCallable, Empty
from litestar.types.builtin_types import NoneType
from litestar.utils.predicates import is_async_callable
Expand Down

0 comments on commit 7365d41

Please sign in to comment.