routes

class litestar.routes.ASGIRoute[源代码]

基类:BaseRoute[HTTPScope | WebSocketScope]

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, Generic[ScopeT]

Base Route class used by Litestar.

It's an abstract class meant to be extended.

__init__(*, path: str) None[源代码]

Initialize the route.

参数:

path -- Base path of the route

abstractmethod async handle(scope: ScopeT, 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[HTTPScope]

An HTTP route, capable of handling multiple HTTPRouteHandlers.

__init__(*, path: str, route_handlers: Iterable[HTTPRouteHandler]) None[源代码]

Initialize HTTPRoute.

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

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

class litestar.routes.WebSocketRoute[源代码]

基类:BaseRoute[WebSocketScope]

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