Builtin Library
README.md
request
User-scope entry point for authenticated BYO-key egress (Mechanism B).
World code calls request.json(...) / request.bytes(...) instead of using
http directly whenever a call needs a world-owned secret. (The built-in
.service assets do not use this — they run on the credit-metered path via
Service.invoke; see modules.serviceCall.)
Exports
request.json(credential, method, url, body?, headers?) -> (table?, string?)request.bytes(credential, method, url, body?, headers?) -> (string?, string?)
Both return (result) on success or (nil, errMessage) on failure.
How it works
request.json("my_api", ...) ← userspace (this module)
│
▼
egress.fetch("my_api", ...) ← Rust primitive
│ looks up the named credential the trusted VM registered,
│ appends the auth header in Rust, performs the call
▼
upstream API (production: the ZeroMind egress endpoint)
The secret is never visible to userspace — you only ever name the
credential (e.g. "my_api"). The engine injects the header in Rust and
returns only the response. The credential carries an allowed host prefix,
so a named credential can't be used to send the key to an arbitrary URL.
When NOT to use it
Downloading a finished asset from a returned public / signed CDN URL does
not need a credential (and that URL is usually on a different host than
the API). Use http.get_bytes(url) directly for those.
Errors
request.* returns nil, err rather than raising, so handlers can do:
local data, err = request.json("my_api", "POST", url, body)
if not data then
handle:fail(err)
return
end
Common errors: the credential isn't configured (no V1 secret set / no ZeroMind secret), the URL isn't under the credential's allowed host, or the upstream returned an HTTP error (surfaced as the error message).