VeloxServe

实验性的,轻量级的 Swift HTTP 服务器,构建于 SwiftNIO 之上,具有完全异步的 API。

示例

您可以通过向服务器提供一个异步函数 (RequestReader, inout ResponseWriter) async throws -> Void 来响应 HTTP 请求。在此函数中,您可以从给定的 RequestReader 结构体中读取请求,并将您的响应写入 ResponseWriter 结构体。从该函数返回(或抛出错误)表示您已完成响应。

import VeloxServe

let server = Server(
    host: "localhost", 
    port: 8080) { req, res in 
    try await res.plainText("Hello, World!\r\n")
}

try await server.run()