Liking cljdoc? Tell your friends :D

unirate.client

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.
raw docstring

unirate.errors

Error model for the UniRate API client.

Every error the client raises is a clojure.lang.ExceptionInfo (created with ex-info) carrying a :unirate/error-type keyword in its ex-data. A caller can therefore catch clojure.lang.ExceptionInfo to handle any failure, or branch on the error type:

(try
  (unirate.client/get-rate client "USD" "EUR")
  (catch clojure.lang.ExceptionInfo e
    (case (:unirate/error-type (ex-data e))
      :authentication  (handle-bad-key)
      :rate-limit      (back-off)
      :invalid-currency (warn)
      (rethrow e))))

The keyword set is the Clojure equivalent of the typed exception hierarchy in the other UniRate clients:

error-typeHTTPmeaning
:invalid-date400malformed date / invalid request params
:authentication401missing or invalid API key
:invalid-currency404unknown currency or no data available
:rate-limit429request quota exceeded
:api*any other non-2xx (403 Pro-gate, 503, ...)
:uniratetransport / parse / generic failure (base)
Error model for the UniRate API client.

Every error the client raises is a `clojure.lang.ExceptionInfo` (created with
`ex-info`) carrying a `:unirate/error-type` keyword in its `ex-data`. A caller
can therefore catch `clojure.lang.ExceptionInfo` to handle any failure, or
branch on the error type:

    (try
      (unirate.client/get-rate client "USD" "EUR")
      (catch clojure.lang.ExceptionInfo e
        (case (:unirate/error-type (ex-data e))
          :authentication  (handle-bad-key)
          :rate-limit      (back-off)
          :invalid-currency (warn)
          (rethrow e))))

The keyword set is the Clojure equivalent of the typed exception hierarchy in
the other UniRate clients:

| error-type        | HTTP | meaning                                    |
|-------------------|------|--------------------------------------------|
| :invalid-date     | 400  | malformed date / invalid request params    |
| :authentication   | 401  | missing or invalid API key                 |
| :invalid-currency | 404  | unknown currency or no data available      |
| :rate-limit       | 429  | request quota exceeded                      |
| :api              | *    | any other non-2xx (403 Pro-gate, 503, ...) |
| :unirate          | —    | transport / parse / generic failure (base) |
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close