base#

class starlite.handlers.base.BaseRouteHandler#

Bases: Generic[T]

Base route handler.

Serves as a subclass for all route handlers

__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 HTTPRouteHandler.

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.

property handler_name: str#

Get the name of the handler function.

Raises:

ImproperlyConfiguredException – if handler fn is not set.

Returns:

Name of the handler function

property dependency_name_set: Set[str]#

Set of all dependency names provided in the handler’s ownership layers.

property ownership_layers: List[Union[T, Controller, Router]]#

Return the handler layers from the app down to the route handler.

app -> … -> route handler

resolve_layered_parameters() Dict[str, SignatureField]#

Return all parameters declared above the handler.

resolve_guards() List[Callable[[Any, Any], Union[None, Awaitable[None]]]]#

Return all guards in the handlers scope, starting from highest to current layer.

resolve_dependencies() Dict[str, Provide]#

Return all dependencies correlating to handler function’s kwargs that exist in the handler’s scope.

resolve_middleware() 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]]]#

Build the middleware stack for the RouteHandler and return it.

The middlewares are added from top to bottom (app -> router -> controller -> route handler) and then reversed.

resolve_exception_handlers() Dict[Union[int, Type[Exception]], Callable[[Any, _ExceptionT], Any]]#

Resolve the exception_handlers by starting from the route handler and moving up.

This method is memoized so the computation occurs only once.

resolve_opts() None#

Build the route handler opt dictionary by going from top to bottom.

If multiple layers define the same key, the value from the closest layer to the response handler will take precedence.

async authorize_connection(connection: ASGIConnection) None#

Ensure the connection is authorized by running all the route guards in scope.

__str__() str#

Return a unique identifier for the route handler.

Returns:

A string