Search code examples
jsonclojurecompojurering

Compojure ring-json not returning json


I have this small program set up-- expecting the /hello-world endpoint to return JSON, but the HTTP body is empty...

Know why its not returning anything?

(ns easycharge.core
  (:use ring.util.response)
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [easycharge.routes.payments :as payments]
            [easycharge.db.conn :as db]
            [ring.middleware.defaults :refer :all]
            [ring.middleware.json :as middleware]
            [ring.middleware.cors :refer [wrap-cors]]
             )
  (:gen-class))

(defn std-redirect [] (redirect "https://www.hi.com/404/"))

(defroutes app-routes
           (GET "/payments/:env/:id" [env id] {:hi "there"})
           (GET "/hello-world" [] {:msg "hello-world"})
          ;; (payments/get-payment env id)

           ;; serves anything in resources/public
           (route/resources "/")
           (route/not-found (std-redirect)))

(def app (->
           app-routes
           (wrap-cors :access-control-allow-origin [#".*"]
                      :access-control-allow-methods [:get :put :post :delete])
           (middleware/wrap-json-body {:keywords? true :bigdecimals? true})
           (middleware/wrap-json-response)
           (wrap-defaults site-defaults)))

Solution

  • The problem was I wasn't passing my response objects into the (response) fn.

    For example, the hello-world route should've been:

    (GET "/hello-world" [] (response {:msg "hello-world"}))