I am using Clojure and leinigen to build a backend project.
This is a simplified version of my file:
(ns simplified...
(:require [ring.middleware.json :refer [wrap-json-response]]
[ring.util.response :refer [response]]
[ring.middleware.json :refer [wrap-json-body]]
[ring.middleware.defaults :refer [wrap-defaults]]
[ring.adapter.jetty :as jetty]))
(defroutes rest-api-routes
(POST "/api" req
(clojure.pprint/pprint req)
"hello"))
(defn import-atb
[request-id tenant-id]
(let [trial-balance-report (middleware/wrap-json-body rest-api-routes {:keywords? true})])
trial-balance-report)
After doing a lein clean, when I run lein repl, I get:
#error {
:cause No such namespace: middleware
What is wrong with my file?
The quick fix is to substitute
middleware/wrap-json-bodyforwrap-json-bodybecause it's been referred into the namespace.requirecan take an:referoption. The:referoption, which you're using here, allows you to refer to that namespace's var directly from your own. The:asoption will allow you to alias a namespace within your own. For example, you could(:require [ring.middleware.json :as ring-json])and then refer toring-json/wrap-json-bodyin your namespace.