Transport for the GLEIF API: the settings resolver (per-call opts first, then context variables, then defaults), a typed HttpError, JSON GETs, and query-string building that drops unset values.

opts keyContext variableDefault
base-urlgleif.base-urlhttps://api.gleif.org/api/v1

GLEIF takes no credential, so a per-call base-url needs none.

Context Vars

Optional
  • gleif.base-url

Values

BASE_URL

BASE_URL: Str "https://api.gleif.org/api/v1"

PACKAGE_AGENT

PACKAGE_AGENT: Str "hot-dev-gleif-pkg/0.1 (+https://hot.dev)"

SOURCE

SOURCE: Str "gleif"

Functions

body-detail

fn (body: Any): Str?

get-json

fn (url: Str, headers: Map): Any

GET a JSON resource and return the decoded body, or an Err carrying HttpError.

get-json-or-null

fn (url: Str, headers: Map): Any

get-json, but a 404 gives null (an absent parent or record) instead of an Err.

given

fn (v: Any): Bool

True for a non-null value that is not a blank string.

http-error

fn (response: ::hot::http/HttpResponse, url: Str): HttpError

Build an HttpError from a non-2xx response. Exposed for testing; every request uses it.

is-not-found

fn (e: Any): Bool

True when e is an HttpError with status 404.

path-segment

fn (value: Any): Str

Percent-encode one path segment.

pick

fn (opts: Map, key: Str, ctx-key: Str, default: Any): Any

query-string

fn (params: Map): Str

Build a ?a=1&b=2 suffix from a Map, dropping null and blank values (pure); "" when nothing remains. Keys may contain brackets (filter[fulltext], page[size]) and are encoded.

request

fn (method: Str, url: Str, headers: Map): ::hot::http/HttpResponse

GET (or another method) a GLEIF URL with headers, returning the HttpResponse on 2xx or an Err carrying HttpError. A transport failure passes through as its own Err.

resolve

fn (opts: Map): Map

Resolve settings for one call: {base-url}. A value in opts wins over context.

Example

cfg ::gleif::api/resolve({base-url: "https://gleif-proxy.example/api/v1"})

retry-after

fn (headers: Map): Int?

strip-slash

fn (url: Str): Str

Types

HttpError

HttpError type {
    source: Str,
    status: Int,
    url: Str,
    headers: Map,
    body: Any,
    retry-after: Int?,
    message: Str
}

A non-2xx GLEIF response. source is "gleif"; url the requested URL (GLEIF takes no credentials in URLs); retry-after the parsed Retry-After seconds on 429s; message a one-line summary that never includes credentials.