httpbeastNim 實(shí)現(xiàn)的高性能多線程 HTTP 服務(wù)器
httpbeast 是使用 Nim 語(yǔ)言編寫(xiě)的高性能、多線程 HTTP 1.1 服務(wù)器。
主要特性
- 基于 Nim
selectors模塊構(gòu)建,可以有效地利用 Linux 上的 epoll 和 macOS 上的 kqueue - 自動(dòng)并行化,只需確保編譯時(shí)添加
--threads:on參數(shù)即可 - 支持 HTTP pipelining
- 按需使用的解析器,可用于僅解析請(qǐng)求的數(shù)據(jù)
- 與 Nim 的集成
asyncdispatch支持在必要時(shí)在請(qǐng)求回調(diào)中使用 async/await
示例代碼
創(chuàng)建helloHttp.nimble文件:
# Package
version = "0.1.0"
author = "Your Name"
description = "Your Description"
license = "MIT"
srcDir = "src"
bin = @["helloHttp"]
# Dependencies
requires "nim >= 1.0.0"
requires "httpbeast >= 0.3.0"
創(chuàng)建src/helloHttp.nim文件:
import options, asyncdispatch
import httpbeast
proc onRequest(req: Request): Future[void] =
if req.httpMethod == some(HttpGet):
case req.path.get()
of "/":
req.send("Hello World")
else:
req.send(Http404)
run(onRequest)
通過(guò)nimble c -r helloHttp.nim運(yùn)行。
評(píng)論
圖片
表情
