【问题标题】:Compojure ring-json not returning jsonCompojure ring-json 不返回 json
【发布时间】:2015-11-26 03:06:09
【问题描述】:

我设置了这个小程序——期望 /hello-world 端点返回 JSON,但 HTTP 正文为空...

知道为什么它没有返回任何东西吗?

(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)))

【问题讨论】:

    标签: json clojure compojure ring


    【解决方案1】:

    问题是我没有将我的响应对象传递给(response) fn。

    例如,hello-world 路由应该是:

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

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 2018-12-27
      • 2012-03-28
      • 2014-11-25
      • 2015-06-23
      • 2018-09-03
      • 2013-07-18
      • 2014-04-21
      • 2011-04-21
      相关资源
      最近更新 更多