json - Compojure ring-json 不返回 json

标签 json clojure compojure ring

我设置了这个小程序——期望/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)))

最佳答案

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

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

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

关于json - Compojure ring-json 不返回 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32322110/

相关文章:

deployment - 如何将 clojure Web 应用程序部署到 Amazon EC2(AWS Elastic Beanstalk + Leiningen + Compojure + Ring + Tomcat)

java - 附加到 JSONObject,使用 Java 的 org.json 将对象写入文件?

JQuery.ajax 适用于除 IE 之外的所有平台

Clojure 的 :require and Instaparse

windows - Clojure(需要'examples.introduction)返回FileNotFound异常

jQuery CORS 请求因 FireFox 中的预检选项请求而终止

clojure - 在 Compojure 中默认提供 index.html

javascript - 如何向由对象数组组成的 JSON 对象的根添加属性?

javascript - 缩短表格中的数据数量

clojure - 有没有 clojure 工具可以查看 Clojure 如何使用 JVM 内存?