Requests for the UN list file: a typed HttpError and text bodies
that survive any content type. The file fits the default 16 MiB
response cap.
Values
USER_AGENT
USER_AGENT: Str "hot-dev-un-sanctions-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
::un::sanctions::http/body-text({body: "<CONSOLIDATED_LIST/>"}) // "<CONSOLIDATED_LIST/>"
::un::sanctions::http/body-text({}) // ""
get-text
fn (url: Str): Str
GET a file as text: the body as a Str, or an Err.
Example
xml ::un::sanctions::http/get-text("https://scsanctions.un.org/resources/xml/en/consolidated.xml")
length(::un::sanctions::xml/records(xml, "INDIVIDUAL"))
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 ::hot::http/HttpResponse({status: 503, headers: {}, body: "down"})
e ::un::sanctions::http/http-error(response, "https://example.com/list.xml")
e.status // 503
e.message // "HTTP 503 from https://example.com/list.xml: down"
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
url "https://scsanctions.un.org/resources/xml/en/consolidated.xml"
response ::un::sanctions::http/request("GET", url, {}, "")
response.status
Types
HttpError
HttpError type {
status: Int,
url: Str,
headers: Map,
body: Any,
message: Str
}
A non-2xx response from the UN list server. url is the requested URL (without credentials); message is a one-line summary.