Internal HTTP request utilities for Postmark API.

Context Vars

Optional
  • postmark.server.token

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

::postmark::api/encode-body("")  // ""
::postmark::api/encode-body({Name: "Ada"})  // "{\"Name\":\"Ada\"}"

request

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, server-token: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str): ::hot::http/HttpResponse

Make an HTTP request with pre-filled service headers. Additional headers can be provided to merge/override defaults. With no token from either place, the call returns an Err (see resolve).

Example

response ::postmark::api/request("GET", `${::postmark/BASE_URL}/server`)
response.body.Name

// One call on a tenant's server, with an extra header
::postmark::api/request("GET", `${::postmark/BASE_URL}/server`, {"X-Trace": "abc"}, "", {
    server-token: ::hot::ctx/get("tenant.postmark.token")
})
Context Vars: postmark.server.token

resolve

fn (opts: Map): Map

The credential for one call: opts over the postmark.server.token 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

::postmark::api/resolve({server-token: "tenant-b-credential"}).server-token  // "tenant-b-credential"
Context Vars: postmark.server.token

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 {server-token: ...}, or an Err when there is none.

A server-token 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

::postmark::api/resolve-from({server-token: "tenant-b-credential"}, {})  // {server-token: "tenant-b-credential"}
::postmark::api/resolve-from({}, {"postmark.server.token": "project-credential"})  // {server-token: "project-credential"}

// A blank credential in opts never falls back to context
is-err(::postmark::api/resolve-from({server-token: ""}, {"postmark.server.token": "project-credential"}))  // true

Types

HttpError

HttpError type {
    status: Int,
    headers: Map,
    body: Any
}