Search code examples
javaclojureleiningenclj-http

Unable to resolve clj-http


I want to use clj-http, so I created a project with lein with these dependencies in project.clj:

(defproject app "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:main app.core
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
          :url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
            [clj-http "2.0.0"]])

src/app/core.clj:

(ns app.core
  (:require [clj-http.client :as client]))

(println client)

(defn -main
  [& args])

when I use lein clean && lein deps && lein run, I get an error message:

Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: client in this context, compiling:(app/core.clj:4:1)
    at clojure.lang.Compiler.analyze(Compiler.java:6543)
    at clojure.lang.Compiler.analyze(Compiler.java:6485)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3791)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6725)
    at clojure.lang.Compiler.analyze(Compiler.java:6524)
    at clojure.lang.Compiler.analyze(Compiler.java:6485)

lein version output:

Leiningen 2.5.3 on Java 1.8.0_45 Java HotSpot(TM) 64-Bit Server VM

Did I make something wrong? I followed exactly the clj-http documentation.

Thank you.


Solution

  • Requiring [clj-http.client :as client] lets you refer to Vars defined in that namespace using client as a prefix. For example, you could say

    (client/get "http://example.com/")
    

    and get back a response.

    This usage, however, is unrelated to using the symbol client to refer to a Var or a local, and so this isn't going to work:

    (println client)
    

    client is just a namespace alias registered in the current namespace, and those can't be evaluated.