A pure Nim SSE HTTP client built from scratch over TCP + TLS. Zero third-party dependencies.
- Zero third-party dependencies — uses only the Nim standard library
- Built from scratch — TCP/TLS over
net.Socket, manual HTTP/1.1 parsing - HTTPS support — via the standard
netSSL context, with configurable certificate verification - SSE streaming — incremental Server-Sent Events parser
- jQuery-style chained API —
client("url").get().then(...).catch(...) - Sync + Async dual mode — blocking and non-blocking APIs, both support HTTPS
- Application-level timeouts — independent timeouts for connect, send, and recv
nimble installimport sse_nim_http_client
# Synchronous GET
let res = client("https://api.example.com/data").get()
res.then(proc (r: Response) =
echo r.status # 200
echo r.text() # body text
).catch(proc (e: ref Exception) =
echo e.msg
)
# Chained POST JSON
client("https://api.example.com/users")
.header("Authorization", "Bearer xxx")
.post("""{"name":"nim"}""", "application/json")
.then(proc (r: Response) =
echo r.json()["id"]
)
# SSE streaming
client("https://api.example.com/events")
.sse(proc (ev: SseEvent) =
echo ev.event, ": ", ev.data
)import std/asyncdispatch
import sse_nim_http_client
proc main() {.async.} =
let res = await client("https://api.example.com/data")
.timeout(5000)
.getAsync()
echo res.status
echo res.text()
waitFor main()# Sync: connect, send, and recv are all governed by timeout
client("https://api.example.com/data")
.timeout(5000) # 5-second timeout
.get()
# Async: also supported
await client("https://api.example.com/data")
.timeout(5000)
.getAsync()client("https://self-signed.local")
.insecure() # skip HTTPS certificate verification
.get()src/
├── sse_nim_http_client.nim # Main entry / jQuery-style API
├── core/
│ ├── url.nim # URL parser
│ ├── connection.nim # TCP connection (with timeout)
│ └── request.nim # HTTP request builder
├── protocols/
│ └── http11.nim # HTTP/1.1 response parser (with chunked)
├── streaming/
│ └── sse.nim # SSE incremental parser
└── ssl/
└── openssl.nim # TLS/SSL wrapper
# -d:ssl is required to enable HTTPS support
nim c -d:ssl your_app.nimnimble testMIT