Liking cljdoc? Tell your friends :D


A client for API based on clj-http.client.

CircleCI Dependencies Status License


[clj-currencylayer "0.2.0"]


All functions are designed to return errors instead of throwing exceptions (except :pre in a function).

All API calls return a tuple within following structure: [:keyword body response] where:keyword can be:

  • :ok when a response is a success and parsed
  • :error-XXX when a response is parsed but it's an error response (where XXX is an error code from error codes)
  • :error-unmarshalling when a response is not a valid JSON

A body is a parsed body and response is an original response.

To be able to run examples this line is needed:

(require '[clj-currencylayer.core :as currencylayer])


Returns the most recent exchange rate data. Pass all parameters via params hash-map.

(currencylayer/get-live {:access_key "asdf", :source "USD", :currencies ["EUR" "CZK"]})
;; [:ok
;;  {:success true, :timestamp 1521448156, :source "USD", :quotes {:USDCZK 20.7104, :USDEUR 0.814495}, ...
;;  {:request-time 386, ...

:currencies are joined automatically, thus you can pass them as a sequence

(currencylayer/get-live {:access_key "asdf"} ["EUR" "CZK"])

Because of a tuple you can do kind of "pattern matching":

(let [[status body _] (:currencylayer/get-live {:access_key "asdf", :source "EUR", :currencies ["CZK"]})]
  (case status
    :ok (process-currencies body)
    :error-101 (missing-auth-key body)
    (default-error body)))

When you need to mock a response, you can pass a host to a caller

(currencylayer/get-live {:access_key "asdf"} "my-mock-domain.localhost")

Or for development you can use HTTP host

(currencylayer/get-live {:access_key "asdf"} currencylayer/currencylayer-host-http)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close