routes#

class litestar.routes.BaseRoute#

Bases: ABC

Base Route class used by Litestar.

It’s an abstract class meant to be extended.

__init__(*, handler_names: list[str], path: str, scope_type: ScopeType, methods: list[Method] | None = None) None#

Initialize the route.

Parameters:
  • handler_names – Names of the associated handler functions

  • path – Base path of the route

  • scope_type – Type of the ASGI scope

  • methods – Supported methods

abstract async handle(scope: Scope, receive: Receive, send: Send) None#

ASGI App of the route.

Parameters:
  • scope – The ASGI connection scope.

  • receive – The ASGI receive function.

  • send – The ASGI send function.

Returns:

None

class litestar.routes.ASGIRoute#

Bases: BaseRoute

An ASGI route, handling a single ASGIRouteHandler

__init__(*, path: str, route_handler: ASGIRouteHandler) None#

Initialize the route.

Parameters:
async handle(scope: Scope, receive: Receive, send: Send) None#

ASGI app that authorizes the connection and then awaits the handler function.

Parameters:
  • scope – The ASGI connection scope.

  • receive – The ASGI receive function.

  • send – The ASGI send function.

Returns:

None

class litestar.routes.WebSocketRoute#

Bases: BaseRoute

A websocket route, handling a single WebsocketRouteHandler

__init__(*, path: str, route_handler: WebsocketRouteHandler) None#

Initialize the route.

Parameters:
async handle(scope: WebSocketScope, receive: Receive, send: Send) None#

ASGI app that creates a WebSocket from the passed in args, and then awaits the handler function.

Parameters:
  • scope – The ASGI connection scope.

  • receive – The ASGI receive function.

  • send – The ASGI send function.

Returns:

None

class litestar.routes.HTTPRoute#

Bases: BaseRoute

An HTTP route, capable of handling multiple HTTPRouteHandlers.

__init__(*, path: str, route_handlers: list[litestar.handlers.http_handlers.base.HTTPRouteHandler]) None#

Initialize HTTPRoute.

Parameters:
async handle(scope: HTTPScope, receive: Receive, send: Send) None#

ASGI app that creates a Request from the passed in args, determines which handler function to call and then handles the call.

Parameters:
  • scope – The ASGI connection scope.

  • receive – The ASGI receive function.

  • send – The ASGI send function.

Returns:

None

create_handler_map() None#

Parse the router_handlers of this route and return a mapping of http- methods and route handlers.

create_options_handler(path: str) HTTPRouteHandler#
Parameters:

path – The route path

Returns:

An HTTP route handler for OPTIONS requests.