HttpServerAdapter 類別

針對特定框架的 HTTP 伺服器介面卡的協定。

實作這個轉接器,可以插入任何 HTTP 框架(FastAPI、Starlette、Flask 等)。 SDK 會以框架無關 HttpRequest/HttpResponse 的物件呼叫這些方法,讓介面卡能夠與底層框架進行轉換。

建構函式

HttpServerAdapter(*args, **kwargs)

方法

register_route

註冊一個路由處理程序員。 Required.

serve_static

從目錄中提供靜態檔案。 可選——預設 no-op。

start

啟動伺服器。 可選性——如果不實施,將加薪。

stop

停止伺服器。 可選——預設 no-op。

register_route

註冊一個路由處理程序員。 Required.

register_route(method: Literal['POST'], path: str, handler: HttpRouteHandler) -> None

參數

名稱 Description
method
必要
path
必要
handler
必要

serve_static

從目錄中提供靜態檔案。 可選——預設 no-op。

serve_static(path: str, directory: str) -> None

參數

名稱 Description
path
必要
directory
必要

start

啟動伺服器。 可選性——如果不實施,將加薪。

async start(port: int) -> None

參數

名稱 Description
port
必要

stop

停止伺服器。 可選——預設 no-op。

async stop() -> None