routes

class litestar.routes.ASGIRoute

Bases: BaseRoute[Union[HTTPScope, WebSocketScope]]

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.BaseRoute

Bases: ABC, Generic[ScopeT]

Base Route class used by Litestar.

It’s an abstract class meant to be extended.

__init__(*, path: str) None

Initialize the route.

Parameters:

path – Base path of the route

abstract async handle(scope: ScopeT, 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.HTTPRoute

Bases: BaseRoute[HTTPScope]

An HTTP route, capable of handling multiple HTTPRouteHandlers.

__init__(*, path: str, route_handlers: Iterable[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(route_handlers: Iterable[HTTPRouteHandler]) dict[HttpMethodName, HTTPRouteHandler]

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

class litestar.routes.WebSocketRoute

Bases: BaseRoute[WebSocketScope]

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