veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

net/client

lib/net/client.vk

lib/net/client.vk Unified 3-track pure-Veko HTTP/1.1 + HTTPS (TLS 1.3 / PQC) client. Works identically across --vm, --wasm, and --native with automatic redirect following (301/302/307/308), timeouts, Bearer/Basic auth helpers, JSON request/response helpers, and transparent gzip/deflate response decompression.

signature
RequestOpts = struct { headers map[str] = ..., timeout dur = ..., max_redirects i64 = ..., roots_pem str = ..., extra_roots_pem str = ..., ca_file str = ..., pins_sha256 block = ..., pqc bool = ... }

Request options with ergonomic defaults.

signature
HttpResponse = struct { status i64, reason str, headers map[str], body bytes, final_url str }

Structured HTTP response returned by request, get, post, and post-json.

signature
bearer-header = fn [token str] map[str]

Returns a header map with Authorization: Bearer <token>.

signature
basic-header = fn [user str, password str] map[str]

Returns a header map with RFC 7617 Authorization: Basic <base64(user:pass)>.

Executable Example
veko
use [hc = net/client]
h = hc/basic-header 'alice' 'secret'
if (map/get h 'Authorization') != 'Basic YWxpY2U6c2VjcmV0' [ err 'basic auth' ] else [ .ok ]
signature
header = fn [resp HttpResponse, name str, default_val str] str

Looks up a response header case-insensitively (returns default_val if absent).

signature
text-body = fn [resp HttpResponse] str

Returns the response body decoded as a UTF-8 string.

signature
json-body = fn [resp HttpResponse] any

Decodes the response body as JSON.

signature
request = fn [method str, target_url str, body bytes, opts RequestOpts] HttpResponse

Executes an HTTP/HTTPS request with redirect handling (301/302/303/307/308).

get fn
signature
get = fn [target_url str, opts RequestOpts] HttpResponse

Performs an HTTP/HTTPS GET request.

head fn
signature
head = fn [target_url str, opts RequestOpts] HttpResponse

Performs an HTTP/HTTPS HEAD request (returns headers with empty body, preserving Content-Length).

post fn
signature
post = fn [target_url str, body bytes, opts RequestOpts] HttpResponse

Performs an HTTP/HTTPS POST request with raw body bytes.

signature
post-json = fn [target_url str, payload any, opts RequestOpts] HttpResponse

JSON-encodes payload and sends an HTTP/HTTPS POST with Content-Type: application/json.

signature
AsyncRequest = struct { method str = ..., url str, headers map[str] = ..., body bytes = ..., timeout dur = ... }

Descriptor for one concurrent non-blocking HTTP/1.1 request in request-batch.

request-batch fn caps: .clocks .net
signature
request-batch = fn [reqs block[AsyncRequest]] block

Executes a batch of HTTP/1.1 AsyncRequests concurrently on a single OS readiness reactor (epoll / kqueue / IOCP+WSAPoll / WASI net-poll) using non-blocking sockets. Returns a block in matching input order where each entry is an HttpResponse or err.

signature
get-many = fn [urls block[str], opts RequestOpts] block

Performs concurrent non-blocking HTTP GET requests for all urls on a single reactor thread.

Pool struct
signature
Pool = struct { idle map, max_idle i64 = ..., reused i64 = ... }

Reusable HTTP/1.1 keep-alive connection pool keyed by scheme://host:port.

signature
new-pool = fn [cap i64] Pool

Creates a new empty HTTP/1.1 connection Pool.

signature
pool-request = fn [mut pool Pool, method str, target_url str, body bytes, opts RequestOpts] HttpResponse

Executes a pooled HTTP/1.1 request reusing or establishing a persistent keep-alive stream.

signature
pool-get = fn [mut pool Pool, target_url str, opts RequestOpts] HttpResponse

Performs a pooled HTTP GET request.

signature
close-pool = fn [mut pool Pool]

Closes all idle keep-alive sockets in pool.