Last updated

🔗Examples

Every example lives in examples/and is runnable as-is. Clone the library repo, then nim c -r any file below. Ignore prebuilt binaries in examples/; only the .nim sources matter.

Each row links to its source on GitHub. The guides throughout these docs explain the interesting parts tour-style with one snippet per feature.

🔗HTTP servers

ExampleDemoSource
httpserver.nimTiny HTTP/1.1 server, manual routingsource
httpserver_threads.nimOne loop per core via SO_REUSEPORTsource
httpserver_multiport.nimOne server on several portssource
httpserver_ktls.nimHTTPS with kernel-TLS offload probesource
http2server.nimHTTP/2 over TLS ( h2) + cleartext ( h2c)source
http2server_threads.nimMulti-threaded HTTP/2 via SO_REUSEPORTsource
static_server.nimStatic site + CORS + JSON APIsource
stream_server.nimstreamFile / sendFile / serveFile, Range and resumesource
stream_server_ktls.nimStreaming and downloads over TLS with kTLSsource
upload_server.nimRaw-body and multipart uploadssource
uds_server.nimHTTP over a Unix domain socketsource
tls_server.nimHTTPS with an embedded self-signed certsource

🔗Clients

ExampleDemoSource
httpclient.nimSync + async HTTP client, pooling, UDSsource

🔗WebSocket

ExampleDemoSource
wsserver.nimStandalone WebSocket serversource
wsclient.nimHigh-level client: reconnect, sendMessagesource
wsupgrade.nimHTTP and WebSocket on one portsource
ws_chat.nimMulti-client chat with broadcastsource

🔗TCP and proxy

ExampleDemoSource
tcp_chat.nimMulti-client chat room on raw TCPsource
tcp_client.nimInteractive stdin client for the chatsource
tcp_proxy.nimLow-level reverse proxy with connect bufferingsource
proxyserver.nimHigh-level ProxyServer reverse proxysource

🔗UDP and DTLS

ExampleDemoSource
udp_echo.nimUDP echo server plus ping client modesource
dtls_echo.nimDTLS 1.2 echo with cookie exchange and MTU splittingsource

🔗Core features

ExampleDemoSource
timers_scheduler.nimTimer wheel: one-shot, interval, deferred, idlesource
fswatch.nimFile system watcher eventssource
os_signals.nimGraceful shutdown on SIGINT / SIGTERMsource
signal_bus.nimIn-process pub/sub SignalRelaysource
stream_pipe.nimIoStream socketpair echo with EOFsource
ratelimit_server.nimSliding-window per-IP rate limitingsource

devcert.nim is a shared helper (throwaway self-signed cert/key), not a standalone demo.

🔗Port map

PortExample
9000httpserver, httpserver_threads, httpserver_multiport, wsupgrade, upload_server
9001wsserver, httpserver_multiport (second port), proxyserver backend
9002stream_server (needs the ~2.76 GB .webm)
9003ratelimit_server
9004static_server
9005signal_bus
9006ws_chat
9007os_signals
9010tcp_chat and tcp_client
9011udp_echo
9012dtls_echo
9020 / 9021tcp_proxy, proxyserver and their backends
9040http2server ( h2 over TLS by default, --h2c for cleartext)
9443tls_server
9444httpserver_ktls
nonetimers_scheduler, fswatch, stream_pipe, httpclient
UDS pathuds_server ( /tmp/powpow.sock)

🔗Quick smoke test

# HTTP server
curl http://localhost:9000/
curl http://localhost:9000/api/echo -d 'Hello powpow!'

# WebSocket
websocat ws://localhost:9001          # or: npx wscat -c ws://localhost:9001

# TCP chat
nc 127.0.0.1 9010

# UDP
echo "hello udp" | nc -u -w1 127.0.0.1 9011
nim c -r examples/udp_echo.nim -- --client

# TLS and DTLS
curl -k https://localhost:9443/hello
nim c -r examples/dtls_echo.nim -- --client

# HTTP/2 (cleartext)
curl --http2-prior-knowledge http://localhost:9040/hello

# UDS
curl --unix-socket /tmp/powpow.sock http://localhost/hello

# Rate limiting (429 after the 5th request)
for i in $(seq 6); do curl -s -o /dev/null -w "%{http_code}\n" http://localhost:9003/; done

# Uploads
curl -X POST http://localhost:9000/upload/raw --data-binary @bigfile.bin
curl -X POST http://localhost:9000/upload/stream -F "file=@bigfile.bin"