Internal HTTP request utilities for the Resend API.
Context Vars
resend.api.key
Functions
encode-body
fn (body: Any): Str
The wire form of a request body: "" means no body at all, anything
else is JSON. Exposed for testing.
Example
::resend::api/encode-body("") // ""
::resend::api/encode-body({name: "Ada"}) // "{\"name\":\"Ada\"}"
request
fn (method: Str, url: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, api-key: Str): ::hot::http/HttpResponse
Make an HTTP request with pre-filled service headers. Additional headers
can be provided to merge/override defaults. With no key from either
place, the call returns an Err (see resolve).
Example
response ::resend::api/request("GET", `${::resend/BASE_URL}/domains`)
response.body.data
// One call with a tenant's key
::resend::api/request("POST", `${::resend/BASE_URL}/audiences`, {}, {name: "Newsletter"}, {
api-key: ::hot::ctx/get("tenant.resend.key")
})
resend.api.key
resolve
fn (opts: Map): Map
The credential for one call: opts over the resend.api.key context variable
(see resolve-from). Per-call credentials stay in the call; nothing is
written to ctx, so parallel flows and tenants never share them.
A credential from opts is masked in the run's call records.
Example
::resend::api/resolve({api-key: "tenant-b-credential"}).api-key // "tenant-b-credential"
resend.api.key
resolve-from
fn (opts: Map, ctx-values: Map): Map
The one resolver, pure: the credential for a call from opts first,
then ctx-values (a Map of context variables). Returns {api-key: ...}, or
an Err when there is none.
A api-key key in opts always decides the call. If its value is null or
blank that is an Err, never a fallback to context, so a tenant whose
stored credential is missing can't silently run on the project's
credential. Nothing is written to ctx. Exposed for testing; resolve
feeds it the context.
Example
::resend::api/resolve-from({api-key: "tenant-b-credential"}, {}) // {api-key: "tenant-b-credential"}
::resend::api/resolve-from({}, {"resend.api.key": "project-credential"}) // {api-key: "project-credential"}
// A blank credential in opts never falls back to context
is-err(::resend::api/resolve-from({api-key: ""}, {"resend.api.key": "project-credential"})) // true
Types
HttpError
HttpError type {
status: Int,
headers: Map,
body: Any
}