Skip to main content

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

NameTypeDescription
pathstrThe URL path for the WebSocket route.
endpointCallable[..., Any]The callable that will handle WebSocket connections.
name`strNone` = None
dependencies`Sequence[params.Depends]None` = None
dependency_overrides_provider`AnyNone` = 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

NameTypeDescription
scopeScopeThe ASGI scope dictionary representing the incoming request or connection, used to determine if the route matches.

Returns

TypeDescription
tuple[Match, Scope]A tuple containing a Match enum indicating if the route matched, and the potentially updated child scope.