路由

class litestar.routes.ASGIRoute

基类:BaseRoute

An ASGI route, handling a single ASGIRouteHandler

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

Initialize the route.

参数:
async handle(scope: Scope, receive: Receive, send: Send) None

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

参数:
  • scope -- The ASGI connection scope.

  • receive -- The ASGI receive function.

  • send -- The ASGI send function.

返回:

None

class litestar.routes.BaseRoute

基类: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.

参数:
  • handler_names -- Names of the associated handler functions

  • path -- Base path of the route

  • scope_type -- Type of the ASGI scope

  • methods -- Supported methods

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

ASGI App of the route.

参数:
  • scope -- The ASGI connection scope.

  • receive -- The ASGI receive function.

  • send -- The ASGI send function.

返回:

None

class litestar.routes.HTTPRoute

基类:BaseRoute

An HTTP route, capable of handling multiple HTTPRouteHandlers.

__init__(*, path: str, route_handlers: list[HTTPRouteHandler]) None

Initialize HTTPRoute.

参数:
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.

参数:
  • scope -- The ASGI connection scope.

  • receive -- The ASGI receive function.

  • send -- The ASGI send function.

返回:

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
参数:

path -- The route path

返回:

An HTTP route handler for OPTIONS requests.

class litestar.routes.WebSocketRoute

基类:BaseRoute

A websocket route, handling a single WebsocketRouteHandler

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

Initialize the route.

参数:
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.

参数:
  • scope -- The ASGI connection scope.

  • receive -- The ASGI receive function.

  • send -- The ASGI send function.

返回:

None