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 -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

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 -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

None

class litestar.routes.HTTPRoute[原始碼]

基底類別:BaseRoute[HTTPScope]

An HTTP route, capable of handling multiple HTTPRouteHandlers.

__init__(*, path: str, route_handlers: Iterable[HTTPRouteHandler]) None[原始碼]

初始化 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 -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

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 -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

None