Transport for the Federal Register 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 and repeats a key for a Vec.
| opts key | Context variable | Default |
|---|---|---|
base-url | federal-register.base-url | https://www.federalregister.gov/api/v1 |
The Federal Register takes no credential, so a per-call base-url
needs none.
Context Vars
federal-register.base-url
Values
BASE_URL
BASE_URL: Str "https://www.federalregister.gov/api/v1"
PACKAGE_AGENT
PACKAGE_AGENT: Str "hot-dev-federal-register-pkg/0.1 (+https://hot.dev)"
SOURCE
SOURCE: Str "federal-register"
Functions
get-json
fn (url: Str): Any
GET a JSON resource and return the decoded body, or an Err carrying
HttpError.
Example
doc ::federal-register::api/get-json("https://www.federalregister.gov/api/v1/documents/2026-18194.json")
doc.title
get-json-or-null
fn (url: Str): Any
get-json, but a 404 gives null (an absent document) instead of an Err.
Example
doc ::federal-register::api/get-json-or-null("https://www.federalregister.gov/api/v1/documents/2026-18194.json")
if(is-null(doc), "no such document", doc.title)
given
fn (v: Any): Bool
True for a non-null value that is not a blank string or an empty Vec.
Example
::federal-register::api/given(" ") // false
::federal-register::api/given([]) // false
::federal-register::api/given(0) // true
html-error
fn (response: ::hot::http/HttpResponse, url: Str): HttpError
Build an HttpError for an HTML page served in place of API data.
Exposed for testing.
Example
response {status: 200, headers: {}, body: "<html></html>"}
e ::federal-register::api/html-error(response, "https://www.federalregister.gov/api/v1/agencies.json")
e.status // 200
contains(e.message, "HTML") // true
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: 400, headers: {}, body: {errors: {agencies: "invalid value"}}}
e ::federal-register::api/http-error(response, "https://www.federalregister.gov/api/v1/documents.json")
e.status // 400
e.message // "federal-register: HTTP 400: agencies: invalid value"
is-html
fn (response: Any): Bool
True when a response is an HTML page (pure). No endpoint here serves
HTML on success, so a 200 page means the request was sent somewhere
else. The site redirects clients it flags as automated to a CAPTCHA
page, and ::hot::http follows the redirect.
Example
::federal-register::api/is-html({headers: {content-type: "text/html; charset=utf-8"}}) // true
::federal-register::api/is-html({headers: {content-type: "application/json"}}) // false
is-not-found
fn (e: Any): Bool
True when e is an HttpError with status 404.
Example
::federal-register::api/is-not-found({status: 404}) // true
::federal-register::api/is-not-found({status: 500}) // false
path-segment
fn (value: Any): Str
Percent-encode one path segment.
Example
::federal-register::api/path-segment("2026 18194") // "2026%2018194"
query-string
fn (params: Map): Str
Build a ?a=1&b=2 suffix from a Map, dropping null, blank and empty
values (pure); "" when nothing remains. A Vec repeats its key, as
conditions[agencies][] needs, and keys are encoded.
Example
::federal-register::api/query-string({order: "newest", term: null, page: 2}) // "?order=newest&page=2"
::federal-register::api/query-string({"fields[]": ["title", "type"]}) // "?fields%5B%5D=title&fields%5B%5D=type"
::federal-register::api/query-string({term: " "}) // ""
request
fn (url: Str, headers: Map): ::hot::http/HttpResponse
GET a Federal Register URL with headers, returning the
HttpResponse on 2xx or an Err carrying HttpError. An HTML page is
an Err too. A transport failure passes through as its own Err.
Example
response ::federal-register::api/request(
"https://www.federalregister.gov/api/v1/agencies.json",
{Accept: "application/json"}
)
response.status
resolve
fn (opts: Map): Map
Resolve settings for one call: {base-url}. A value in opts wins
over context.
Example
cfg ::federal-register::api/resolve({base-url: "https://fr-proxy.example/api/v1"})
Types
HttpError
HttpError type {
source: Str,
status: Int,
url: Str,
headers: Map,
body: Any,
retry-after: Int?,
message: Str
}
A failed Federal Register response. source is "federal-register";
url the requested URL (the API takes no credentials in URLs);
retry-after the parsed Retry-After seconds on 429s; message a
one-line summary that never includes credentials. status can be 200
when the site served an HTML page in place of API data (see
is-html).