Requests to the Sanctions List Service: a typed HttpError and text bodies that survive any content type. Every file this package uses fits the default 16 MiB response cap.

Values

USER_AGENT

USER_AGENT: Str "hot-dev-ofac-pkg/0.1 (+https://hot.dev)"

Functions

body-text

fn (response: Any): Str

The response body as text: the decoded string when Hot kept it as one, otherwise the body bytes decoded as UTF-8 (a CSV served as application/octet-stream, or a body that happened to parse as JSON).

Example

::ofac::http/body-text({body: "a,b"})  // "a,b"
::ofac::http/body-text({body: [1, 2], body-bytes: Bytes("[1,2]")})  // "[1,2]"

get-text

fn (url: Str): Str

GET a file as text: the body as a Str, or an Err.

Example

csv ::ofac::http/get-text(::ofac/export-url("SDN.CSV"))

// Parse it with the other files, or inspect the text
length(csv)

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

url "https://example.test/x"
response ::hot::http/HttpResponse({status: 404, headers: {}, body: "not here"})
e ::ofac::http/http-error(response, url)
e.status  // 404
e.message  // "HTTP 404 from https://example.test/x: not here"

request

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

One request with the package User-Agent. Returns the HttpResponse on 2xx, or an Err carrying HttpError (transport failures pass through as their own Err).

Example

::http ::ofac::http

// Lists the published files. An Err carries HttpError on a non-2xx status.
response ::http/request(
  "POST",
  "https://sanctionslistservice.ofac.treas.gov/api/PublicationPreview/SdnList",
  {Content-Type: "application/json", Accept: "application/json"},
  "{}"
)
response.body

Types

HttpError

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

A non-2xx response from the Sanctions List Service. url is the requested URL (without credentials); message is a one-line summary.