Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

startvibecoding/SseNimHttpClient

Open more actions menu

Repository files navigation

SseNimHttpClient

A pure Nim SSE HTTP client built from scratch over TCP + TLS. Zero third-party dependencies.

Features

  • 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 net SSL context, with configurable certificate verification
  • SSE streaming — incremental Server-Sent Events parser
  • jQuery-style chained APIclient("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

Installation

nimble install

Quick Start

import 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
  )

Async HTTPS

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()

Timeout Control

# 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()

Skip Certificate Verification (Debug)

client("https://self-signed.local")
  .insecure()      # skip HTTPS certificate verification
  .get()

File Structure

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

Compile

# -d:ssl is required to enable HTTPS support
nim c -d:ssl your_app.nim

Test

nimble test

License

MIT

About

A pure Nim SSE HTTP client built from scratch over TCP + TLS. Zero third-party dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.