ilusm.dev

tls

TLS-oriented HTTP and WebSocket helpers - GET a URL (HTTPS), POST with optional content-type, connect to a WebSocket (ws:// or wss://), bind a WebSocket server, GET and JSON-decode in one call, POST an object as JSON and JSON-decode the response. Thin named aliases over net and jsn.

Load with: use tls

What this module does

tls is a convenience layer that gives TLS-specific names to the underlying net HTTP/WebSocket operations. Use tlsge and tlspo when you want to make it clear that a call is intended for HTTPS endpoints. The JSON helpers tlsge1 and tlspo1 combine fetch + JSON-decode into a single call.

Quick example

use tls

# HTTPS GET
body = tlsge("https://api.example.com/v1/status")

# HTTPS POST
resp = tlspo("https://api.example.com/v1/items", json_body, "application/json")

# GET + JSON decode
data = tlsge1("https://api.example.com/v1/user")
prn(data.name)

# POST object + JSON decode
result = tlspo1("https://api.example.com/v1/create", {name: "Alice"}, nil)

# WebSocket client
ws = tlsws("wss://ws.example.com/stream")

# WebSocket server bind
srv = tlsws1("0.0.0.0:8443")

Functions

HTTP

tlsge(url)

Performs a GET request. Returns the response body string.

tlspo(url, body, opts)

Performs a POST request with body. opts is an optional content-type string.

tlsge1(url)

GET and JSON-decode. Returns the decoded ilusm value.

tlspo1(url, obj, opts)

JSON-encodes obj, POSTs it, and returns the JSON-decoded response.

WebSocket

tlsws(url)

Connects to a WebSocket URL (ws:// or wss://). Returns the connection handle.

tlsws1(bind)

Starts a WebSocket server on the given bind address. Returns the server handle.

Notes

  • Requires net and jsn.