HTTP, Process, Environment, Time & Async
Standard library reference for std/http, std/process, std/environment, std/time, and std/async.
std/http — Bounded HTTP/HTTPS Client
Section titled “std/http — Bounded HTTP/HTTPS Client”Synchronous and parallel-batch HTTP/HTTPS client engineered for bounded API calls with TLS certificate/hostname verification enabled by default.
- Hardened Limits: 8 KiB URL limit, 32 KiB / 100 header limit, 1 MiB request & response body limit, 30s default total timeout, 5s max connect timeout. Redirects and retries are disabled (3xx, 4xx, 5xx are returned as
Responsevalues, not hidden transport errors). - Requirements: Requires
libcurl >= 8.3.0. Unavailable onwasi-command.
import "std/http"import "std/json"
fn fetch_status(url: str) -> str ! http.HttpError { let resp = http.get(url)? let body = http.response_text(resp)? resp.body.close() return f"HTTP {resp.status}: {len(body)} bytes"}Key APIs: make_header, request(url, method, headers, body, timeout_ms, max_response_bytes), get(url), post_json(url, headers, payload), batch_get(urls), batch_get_all(urls), header(resp, name), response_text(resp), response_json(resp).
std/process — Bounded Subprocess Execution
Section titled “std/process — Bounded Subprocess Execution”Executes child programs directly via an argument vector with no implicit shell (eliminating shell injection hazards) and mandatory timeouts (1..600,000 ms, up to 256 arguments).
process.run(executable, arguments, timeout_ms) -> int ! ProcessError— inherits parent stdio and returns exit status.process.capture(executable, arguments, timeout_ms, max_output_bytes) -> ProcessOutput ! ProcessError(v0.8.0) — captures bounded UTF-8stdoutandstderr(1..16,777,216bytes per stream) intoProcessOutput { status: int, stdout: str, stderr: str }.
import "std/process"
fn git_head() -> str ! process.ProcessError { let out = process.capture("git", ["rev-parse", "--short", "HEAD"], 5000, 4096)? return out.stdout}std/environment — Arguments, Env Vars & CWD
Section titled “std/environment — Arguments, Env Vars & CWD”environment.arguments() -> list[str]— runner argument vector ("wysna"at index 0 for interpreted runs).environment.get(name) -> str?— preserves the distinction between missing (none) and empty ("").environment.has(name) -> bool/environment.get_or(name, default) -> str.environment.current_directory() -> str ! FsError.
std/time — Clocks, Monotonic Timers & ISO-8601
Section titled “std/time — Clocks, Monotonic Timers & ISO-8601”time.unix_seconds() -> int/time.now_ms() -> int— host wall clock.time.monotonic_ms() -> int/time.elapsed_ms(start) -> int— monotonic duration measurement.time.sleep(ms) -> unit— blocking sleep.time.from_unix_ms(ms) -> DateTime/time.to_unix_ms(dt) -> int.time.format_iso8601(dt) -> str/time.parse_iso8601(text) -> DateTime ! ParseError.
std/async — Structured Tasks & OS Threads
Section titled “std/async — Structured Tasks & OS Threads”Provides Task[T] handles backed by real OS threads (pthread / CreateThread), cooperative timers, and combinators:
async.ready(val),async.failed(err),async.sleep_ms(ms) -> Task[int],async.spawn(fn() -> T) -> Task[T].async.poll_events(timeout_ms) -> int,async.is_ready(task) -> bool.async.wait(task) -> T ! str,async.all(tasks) -> list[T] ! str,async.race(tasks) -> T ! str.
See Async/Await (CPS) & Parallelism for full usage patterns.