APIWebSocketRoute
This class represents a WebSocket route within an API, associating a specific path with an endpoint callable. It handles dependency injection for WebSocket connections and compiles the path into a regular expression for matching incoming requests.
Constructor
Signature
def APIWebSocketRoute(
path: str,
endpoint: Callable[..., Any],
name: str | None = None,
dependencies: Sequence[params.Depends]| None = None,
dependency_overrides_provider: Any | None = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| path | str | The URL path for the WebSocket route. |
| endpoint | Callable[..., Any] | The callable that will handle WebSocket connections. |
| name | `str | None` = None |
| dependencies | `Sequence[params.Depends] | None` = None |
| dependency_overrides_provider | `Any | None` = None |
Methods
matches()
@classmethod
def matches(
scope: Scope
) - > tuple[Match, Scope]
Determines if the route matches the given scope and updates the child scope with route information if a match is found. This method is called by the routing system to find the appropriate route for an incoming request.
Parameters
| Name | Type | Description |
|---|---|---|
| scope | Scope | The ASGI scope dictionary representing the incoming request or connection, used to determine if the route matches. |
Returns
| Type | Description |
|---|---|
tuple[Match, Scope] | A tuple containing a Match enum indicating if the route matched, and the potentially updated child scope. |