HTTP/1.1
Synchronous#
import serve
serve(8080, proc(req: Request): Response {.closure.} =
ok("hello"))One request handled at a time per connection, in-process — the simplest path, good for internal tools, CLIs and low-traffic services where async complexity isn't worth it.
Async, on the reactor#
import serve, serve/reactor
proc handler(req: Request): Response {.nimcall.} =
response(200, "text/plain", "ok " & req.path & "\n")
serveHttpReactor(8080, handler)For TLS:
serveHttpsReactor(8443, tlsContext, handler)See the repo's reactor_http.nim and reactor_https.nim for complete, runnable versions.
What's included#
Keep-alive, request-size caps returning 413, streamed (non-truncated) responses, and the slowloris guard all apply identically whether you're on the sync or async path — they live in the shared http/tcp layer underneath both.
Routing#
serve doesn't impose a router, but the repo ships a routing example — reactor_router.nim — showing the router tested across all three protocols (HTTP/1.1, HTTP/2, HTTP/3) from one route table.
Related#
- The reactor — the scheduler this server rides on
- TLS and hardening — building the
TlsContext - HTTP/2 — same handler, negotiated over ALPN
