The UniRate API client.
Depends only on the JDK's built-in java.net.http for HTTP and the official
org.clojure/data.json library for decoding, so it pulls in no third-party
runtime code beyond a single Clojure-contrib JSON parser.
A client is a plain map created with make-client; the request functions
take it as their first argument:
(require '[unirate.client :as unirate])
(def client (unirate/make-client "your-api-key"))
(unirate/get-rate client "USD" "EUR") ;; => 0.9321
(unirate/convert client 100 "USD" "EUR") ;; => 93.21
For tests, inject a :transport function (see make-client) so no network
is touched.
The UniRate API client.
Depends only on the JDK's built-in `java.net.http` for HTTP and the official
`org.clojure/data.json` library for decoding, so it pulls in no third-party
runtime code beyond a single Clojure-contrib JSON parser.
A client is a plain map created with [[make-client]]; the request functions
take it as their first argument:
(require '[unirate.client :as unirate])
(def client (unirate/make-client "your-api-key"))
(unirate/get-rate client "USD" "EUR") ;; => 0.9321
(unirate/convert client 100 "USD" "EUR") ;; => 93.21
For tests, inject a `:transport` function (see [[make-client]]) so no network
is touched.(convert client amount from to)(convert client amount from to opts)Convert amount from one currency to another at the current rate. Returns a
double.
Convert `amount` from one currency to another at the current rate. Returns a double.
(convert-historical client amount from to date)(convert-historical client amount from to date opts)Convert amount using the rate from a specific historical date. Returns a
double. Pro-gated.
Convert `amount` using the rate from a specific historical `date`. Returns a double. Pro-gated.
The production UniRate API base URL.
The production UniRate API base URL.
The default per-request timeout, in seconds.
The default per-request timeout, in seconds.
(get-all-rates client)(get-all-rates client base)(get-all-rates client base opts)All current rates for the given base currency (default "USD"). Returns a
{code double} map.
All current rates for the given base currency (default "USD"). Returns a
`{code double}` map.(get-historical-limits client)(get-historical-limits client opts)Per-currency historical coverage. Returns the parsed response map. Pro-gated.
Per-currency historical coverage. Returns the parsed response map. Pro-gated.
(get-historical-rate client date from to)(get-historical-rate client date from to opts)Historical rate for a single from/to pair on date (YYYY-MM-DD). Returns a
double. Pro-gated: raises :api (status 403) on the free tier.
Historical rate for a single from/to pair on `date` (YYYY-MM-DD). Returns a double. Pro-gated: raises `:api` (status 403) on the free tier.
(get-historical-rates client date)(get-historical-rates client date base)(get-historical-rates client date base opts)All historical rates for a base currency on date. Returns a {code double}
map. Pro-gated.
All historical rates for a base currency on `date`. Returns a `{code double}`
map. Pro-gated.(get-rate client from to)(get-rate client from to opts)Current exchange rate from from to to. Codes are uppercased. Returns a
double.
Current exchange rate from `from` to `to`. Codes are uppercased. Returns a double.
(get-supported-currencies client)(get-supported-currencies client opts)The list of supported currency codes, as a vector of strings.
The list of supported currency codes, as a vector of strings.
(get-time-series client start-date end-date)(get-time-series
client
start-date
end-date
{:keys [amount base currencies] :or {amount 1 base "USD"} :as opts})A range of historical rates between two dates (max 5-year span). Returns the
nested data map {date {code double}}. Pass nil/empty :currencies for all
currencies. Pro-gated.
Options map: :amount (default 1), :base (default "USD"),
:currencies (collection of codes), plus :format/:callback.
A range of historical rates between two dates (max 5-year span). Returns the
nested data map `{date {code double}}`. Pass `nil`/empty `:currencies` for all
currencies. Pro-gated.
Options map: `:amount` (default 1), `:base` (default "USD"),
`:currencies` (collection of codes), plus `:format`/`:callback`.(get-vat-rate client country)(get-vat-rate client country opts)VAT data for a single ISO-3166 alpha-2 country code (e.g. "DE"). Returns the
parsed response map ({"country" ... "vat_data" {...}}).
VAT data for a single ISO-3166 alpha-2 country code (e.g. "DE"). Returns the
parsed response map (`{"country" ... "vat_data" {...}}`).(get-vat-rates client)(get-vat-rates client opts)VAT data for every supported country. Returns the parsed response map
({"date" ... "total_countries" ... "vat_rates" {code {...}}}).
VAT data for every supported country. Returns the parsed response map
(`{"date" ... "total_countries" ... "vat_rates" {code {...}}}`).(make-client api-key)(make-client api-key
{:keys [base-url timeout-seconds transport]
:or {base-url default-base-url
timeout-seconds default-timeout-seconds}})Create a client.
api-key is your UniRate API key. The optional second argument is a map of:
:base-url override the API base URL (mainly for tests):timeout-seconds per-request timeout (default 30):transport inject a custom HTTP transport — a function of
[url headers] -> {:status int :body string}; when
omitted the default java.net.http-based transport is
used. Tests use this to run without a network.Create a client.
`api-key` is your UniRate API key. The optional second argument is a map of:
- `:base-url` override the API base URL (mainly for tests)
- `:timeout-seconds` per-request timeout (default 30)
- `:transport` inject a custom HTTP transport — a function of
`[url headers] -> {:status int :body string}`; when
omitted the default `java.net.http`-based transport is
used. Tests use this to run without a network.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |