From ed523cac9f87a7c2c7c2dc946f54b6c4176b0d51 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 Nov 2024 03:22:28 +0100 Subject: [PATCH] refactor notes and passes --- docs/en/docs/release-notes.md | 1 + docs/en/docs/routing/routes.md | 6 +++--- esmerald/routing/router.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index efe439d0..f4b38ea8 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -15,6 +15,7 @@ hide: - Breaking: The `add_pluggable` method is now renamed to `add_extension`. The old name is still available but deprecated. - The documentation will refer now to extensions with `Pluggable` as a setup wrapper. - Allow passing HTTP/WebSocket handlers directly to routes. They are automatically wrapped in Gateways- +- Allow passing HTTP/WebSocket handlers directly to routes as alternative to defining a Gateway/WebsocketGateway. ## 3.4.4 diff --git a/docs/en/docs/routing/routes.md b/docs/en/docs/routing/routes.md index 76a22470..53b78b46 100644 --- a/docs/en/docs/routing/routes.md +++ b/docs/en/docs/routing/routes.md @@ -16,14 +16,14 @@ different APIs and systems, so Esmerald created its own. A Gateway is an extension of the Route, really, but adds its own logic and handling capabilities, as well as its own validations, without compromising the core. -It is automatically added when just passing an HTTP/Websocket handler to routes. +When a handler is passed instead of a Gateway/WebsocketGateway, it will be automatically mapped to the corresponding wrapper and added to the routes. ### Gateway and application In simple terms, a Gateway is not a direct route but instead is a "wrapper" of a [handler](./handlers.md) and maps that same handler with the application routing system. -This allows overwriting options of the handler route specific. +This allows overwriting options of the specific handler route. If not required, you can just pass the handler, it is automatically wrapped in a plain Gateway. #### Parameters @@ -41,7 +41,7 @@ All the parameters and defaults are available in the [Gateway Reference](../refe Same principle as [Gateway](#gateway) with one particularity. Due to the nature of Lilya and websockets we decided not to interfere (for now) with what already works and therefore the only supported websockets are `async`. -This allows overwriting options of the WebsocketHandler route specific. +This allows overwriting options of the specific WebsocketHandler route. If not required, you can just pass the handler, it is automatically wrapped in a plain WebSocketGateway. ### WebSocketGateway and application diff --git a/esmerald/routing/router.py b/esmerald/routing/router.py index 3c045203..ba61c350 100644 --- a/esmerald/routing/router.py +++ b/esmerald/routing/router.py @@ -488,7 +488,7 @@ async def another(request: Request) -> str: for route in routes or []: if isinstance(route, WebhookHandler): # WebhookHandler is a subclass of HTTPHandler, make sure to not upgrade it - pass + ... elif isinstance(route, HTTPHandler): # if using add_route, we would enter a completely different code path with a not fully initialized router route = Gateway(handler=route) @@ -2915,7 +2915,7 @@ def resolve_route_path_handler( for route in routes: # pragma: no cover if isinstance(route, WebhookHandler): # fail later, a WebhookHandler is subclass of HTTPHandler, so pass down - pass + ... elif isinstance(route, HTTPHandler): # if using add_route, we would enter a completely different code path with a not fully initialized router route = Gateway(handler=route)