Transport for the FDIC BankFind Suite 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 key | Context variable | Default |
|---|---|---|
api-key | fdic.bankfind.api-key | none: the API needs no key today |
base-url | fdic.bankfind.base-url | https://api.fdic.gov/banks |
The key goes in the URL. FDIC documents only the api_key query
parameter, so every HttpError field is redacted (redact-url,
redact-value), and api_key is dropped from the parameters a
response echoes in meta.parameters.
Per-call credentials. api-key in opts is masked in call
records and never written to context, so parallel flows and tenants
in one run don't see each other's keys. Present but blank or null, it
is an error, never a fallback to context. A per-call base-url
without an api-key in the same opts sends no key: the context key
is never sent to a per-call URL.
Context Vars
fdic.bankfind.api-keyfdic.bankfind.base-url
Values
BASE_URL
BASE_URL: Str "https://api.fdic.gov/banks"
PACKAGE_AGENT
PACKAGE_AGENT: Str "hot-dev-fdic-bankfind-pkg/0.1 (+https://hot.dev)"
SOURCE
SOURCE: Str "fdic-bankfind"
Functions
decode-body
fn (response: ::hot::http/HttpResponse, url: Str): Any
The decoded JSON of a 2xx response without api_key in
meta.parameters, or an Err carrying HttpError when the body is not
JSON (pure). Exposed for testing.
Example
url "https://api.fdic.gov/banks/failures"
good {status: 200, headers: {}, body: {meta: {total: 1}, data: []}}
::fdic::bankfind::api/decode-body(good, url).meta.total // 1
bad {status: 200, headers: {}, body: "<html></html>"}
is-err(::fdic::bankfind::api/decode-body(bad, url)) // true
drop-key
fn (body: Any): Any
body without api_key in the meta.parameters the API echoes (pure).
Example
::fdic::bankfind::api/drop-key({meta: {parameters: {api_key: "abc", limit: 1}}}) // {meta: {parameters: {limit: 1}}}
get-json
fn (url: Str, headers: Map): Any
GET a JSON resource and return the decoded body, or an Err carrying
HttpError.
Example
page ::fdic::bankfind::api/get-json("https://api.fdic.gov/banks/failures?limit=1", {})
page.meta.total
given
fn (v: Any): Bool
True for a non-null value that is not a blank string.
Example
::fdic::bankfind::api/given("IA") // true
::fdic::bankfind::api/given(" ") // false
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.
Example
response {status: 429, headers: {retry-after: "30"}, body: {message: "Slow down"}}
e ::fdic::bankfind::api/http-error(response, "https://api.fdic.gov/banks/failures?api_key=abc")
e.url // "https://api.fdic.gov/banks/failures?api_key=REDACTED"
e.retry-after // 30
e.message // "fdic-bankfind: HTTP 429: Slow down"
not-json-error
fn (response: ::hot::http/HttpResponse, url: Str): HttpError
An HttpError for a 2xx response that is not JSON, such as a
maintenance page, which would otherwise read as an empty result. Exposed
for testing.
Example
response {status: 200, headers: {}, body: "<html></html>"}
e ::fdic::bankfind::api/not-json-error(response, "https://api.fdic.gov/banks/failures")
e.status // 200
contains(e.message, "expected JSON") // true
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.
Example
::fdic::bankfind::api/query-string({limit: 10, search: "", filters: null}) // "?limit=10"
::fdic::bankfind::api/query-string({search: ""}) // ""
redact
fn (text: Str, api-key: Str?): Str
text with any api_key value and every literal copy of api-key
replaced by REDACTED (pure). api-key may be null.
Example
::fdic::bankfind::api/redact("key abc rejected", "abc") // "key REDACTED rejected"
redact-url
fn (url: Str): Str
url with any api_key value replaced by REDACTED (pure).
Example
::fdic::bankfind::api/redact-url("https://api.fdic.gov/banks/failures?api_key=abc&limit=1")
// "https://api.fdic.gov/banks/failures?api_key=REDACTED&limit=1"
redact-value
fn (value: Any, api-key: Str?): Any
redact over a whole response value: a string, or every string inside a
Map or Vec (pure).
Example
::fdic::bankfind::api/redact-value({url: "/failures?api_key=abc"}, null) // {url: "/failures?api_key=REDACTED"}
request
fn (method: Str, url: Str, headers: Map): ::hot::http/HttpResponse
GET (or another method) a BankFind URL with headers, returning the
HttpResponse on 2xx or an Err carrying HttpError. A transport
failure stays its own Err, with any key redacted.
Example
response ::fdic::bankfind::api/request("GET", "https://api.fdic.gov/banks/failures?limit=1", {Accept: "application/json"})
response.status
resolve
fn (opts: Map): Map
Resolve settings for one call: {api-key, base-url}. Values in
opts win over context; an api-key in opts is used for that call
only and comes back unchanged. api-key is null when none is set,
which the API accepts, and null when opts has a base-url but no
api-key. An Err when api-key is in opts but blank or null.
Example
key ::hot::ctx/get("tenant-b.fdic.api-key")
cfg ::fdic::bankfind::api/resolve({api-key: key})
cfg.base-url
Types
HttpError
HttpError type {
source: Str,
status: Int,
url: Str,
headers: Map,
body: Any,
retry-after: Int?,
message: Str
}
A failed FDIC response. source is "fdic-bankfind"; url the
requested URL with any key redacted; headers and body redacted
too; retry-after the parsed Retry-After seconds on 429s; message
a one-line summary that never includes credentials. status is
normally non-2xx, but it is 200 when the site answered with something
other than JSON (see decode-body).