websocket#

class starlite.handlers.websocket.WebsocketRouteHandler#

Bases: BaseRouteHandler[WebsocketRouteHandler]

Websocket route handler decorator.

Use this decorator to decorate websocket handler functions.

__init__(path: Union[str, None, List[str]] = None, *, dependencies: Optional[Dict[str, Any]] = None, exception_handlers: Optional[Dict[Union[int, Type[Exception]], Callable[[Any, _ExceptionT], Any]]] = None, guards: Optional[List[Callable[[Any, Any], Union[None, Awaitable[None]]]]] = None, middleware: Optional[List[Union[Callable[[...], Callable[[Union[HTTPScope, WebSocketScope], Callable[[...], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]], Awaitable[None]]], Awaitable[None]]], Any, Iterator[Tuple[Callable[[Union[HTTPScope, WebSocketScope], Callable[[...], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebSocketConnectEvent, WebSocketReceiveEvent, WebSocketDisconnectEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebSocketAcceptEvent, WebSocketSendEvent, WebSocketResponseStartEvent, WebSocketResponseBodyEvent, WebSocketCloseEvent]], Awaitable[None]]], Awaitable[None]], Dict[str, Any]]], Type[Any]]]] = None, name: Optional[str] = None, opt: Optional[Dict[str, Any]] = None, **kwargs: Any) None#

Initialize WebsocketRouteHandler

Parameters:
  • path – A path fragment for the route handler function or a list of path fragments. If not given defaults to ‘/’

  • dependencies – A string keyed dictionary of dependency Provider instances.

  • exception_handlers – A dictionary that maps handler functions to status codes and/or exception types.

  • guards – A list of Guard callables.

  • middleware – A list of Middleware.

  • name – A string identifying the route handler.

  • opt – A string keyed dictionary of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

  • **kwargs – Any additional kwarg - will be set in the opt dictionary.

__call__(fn: AsyncAnyCallable) WebsocketRouteHandler#

Replace a function with itself.

starlite.handlers.websocket.websocket#

alias of WebsocketRouteHandler