HttpServerRoute

定义了 HTTP 服务器的路由构建 DSL (领域特定语言)。

此接口提供了一系列方法来构建一个路由树,用于匹配传入请求的 URL 路径和 HTTP 方法, 并将它们分派给相应的处理逻辑。

你通常在 HttpServerConfig.routingroute 方法的 lambda 块中使用它。

Author

M8Test, [email protected], https://m8test.com

Inheritors

Functions

Link copied to clipboard
abstract fun get(path: String, getRouting: HttpServerCall.(CoroutineScope) -> Job): HttpServerRoute

get 是一个便捷方法,用于创建一个匹配 GET 请求和指定路径的路由。

Link copied to clipboard
abstract fun getContext(): ScriptContext

获取脚本上下文对象 ScriptContext.

Link copied to clipboard
abstract fun handle(handleRouting: HttpServerCall.(CoroutineScope) -> Job)

定义当前路由节点的请求处理逻辑。

Link copied to clipboard
abstract fun method(method: (HttpMethods) -> HttpMethod, route: HttpServerRoute.() -> Unit): HttpServerRoute

创建一个 HTTP 方法节点,使其内部的所有路由仅匹配指定的请求方法。

Link copied to clipboard
abstract fun post(path: String, postRouting: HttpServerCall.(CoroutineScope) -> Job): HttpServerRoute

post 是一个便捷方法,用于创建一个匹配 POST 请求和指定路径的路由。

Link copied to clipboard
abstract fun route(path: String, route: HttpServerRoute.() -> Unit): HttpServerRoute

创建一个路径节点,将一组相关的路由组织在同一个 URL 前缀下。

Link copied to clipboard
abstract fun singlePageApplication(config: HttpServerSPAConfig.() -> Unit)

配置一个单页应用(SPA)的静态文件服务。

Link copied to clipboard
abstract fun staticFiles(remotePath: String, rootFolder: ScriptFile, index: String? = "index.html", block: HttpServerStaticContentConfig.() -> Unit?): HttpServerRoute

在指定的 URL 路径下提供静态文件服务。

Link copied to clipboard
abstract fun webSocket(path: String, block: WebSocketSession.(CoroutineScope) -> Job)

在指定的路径上建立一个 WebSocket 端点。