我试图在我的 compojure 应用程序中使用 ring-json 的 wrap-json-response 中间件。我有一个简单的 GET 处理程序,返回类似 {:foo 1}
的映射,当我访问 URL 时,ring 响应 text/plain
和空响应体。我似乎无法让它响应地图的 JSON 版本。
这是我的处理程序代码:
(ns localshop.handler
(:use compojure.core)
(:require [localshop.routes.api.items :as routes-api-items]
[ring.middleware.json :as middleware]
[compojure.handler :as handler]
[compojure.route :as route]))
;; map the route handlers
(defroutes app-routes
(context "/api/item" [] routes-api-items/routes))
;; define the ring application
(def app
(-> (handler/api app-routes)
(middleware/wrap-json-body)
(middleware/wrap-json-params)
(middleware/wrap-json-response)))
路由处理函数实际上只返回一个映射,因此代码简单到我认为可以省略。如果从compojure路由处理程序返回映射是问题所在,那么也许就是这个问题了?
{:body {}}
。 - film42