2

I'm experimenting with Clojure and Leiningen. I was successful in executing to following line in the REPL:

(print (:body (client/get "https://coinbase.com/api/v1/prices/spot_rate?currency=CAD" {:as :json}))

I created a project with lein new http. When I run the following lines witn lein run then the coercion to JSON doesn't work. It simply prints a correct JSON string.

(ns http.core
  (:require [clj-http.client :as client])
  (:use clojure.pprint))

(defn -main
  []
  (print
    (:body
      (client/get "https://coinbase.com/api/v1/prices/spot_rate?currency=CAD" {:as :json}))

the output of the script is

{"amount":"306.89","currency":"CAD"}

Any idea what's wrong?

Steffen Roller
  • 3,464
  • 25
  • 43
  • what version of clj-http are you using. Also, what output are you expecting? – RedDeckWins Aug 21 '15 at 03:50
  • I've got clj-http 2.0.0 configured in my project.clj. But I suspect that the REPL pulls a different version. I don't how to check that. The expected out put would be a Clojure map {:amount "306.89", :currency "CAD} – Steffen Roller Aug 21 '15 at 13:03
  • [typos fixed] I've got clj-http 2.0.0 configured in my project.clj. But I suspect that the REPL pulls a different version. I don't know how to check that. The expected output would be a Clojure map {:amount "306.89", :currency "CAD} – Steffen Roller Aug 21 '15 at 13:15
  • [clj-http "1.1.2"] has the behavior you want. – RedDeckWins Aug 21 '15 at 14:12
  • thank you. That was it it. Seems the 2.0.0 version has a problem. If you'd like to put an official answer in I'll accept and you can earn the rep. – Steffen Roller Aug 21 '15 at 14:57

2 Answers2

4

As it turned out there was a breaking change with clj-http version 2.0.0. Now one has to list explicitly the optional dependencies in project.clj. After I added

[cheshire "5.5.0"]

to my list of dependencies the program worked as expected. Please see the documentation for the change here.

Steffen Roller
  • 3,464
  • 25
  • 43
1

I don't know exactly what changed, but [clj-http "1.1.2"] has the behavior you want.

RedDeckWins
  • 2,111
  • 14
  • 16