我正尝试在 clojure 中使用 ring 制作一个非常简单的 API。我正在使用 rack.middleware.format-params 中间件将输出转换为 json,并将输入从 json 转换为 clojure 数据结构。
我的输出工作得很好,但我终生无法访问通过 json 发送的参数。这是一些适用于获取请求的代码,但我无法获取 POST 请求以返回它收到的 json
(ns testing.core
(:use [compojure.core]
[ring.middleware.format-params :only [wrap-json-params]]
[ring.middleware.format-response :only [wrap-json-response]]
[ring.adapter.jetty])
(:require [compojure.handler :as handler]))
(defroutes app-routes
(GET "/"
[]
{:body {:hello "world"}})
(POST "/"
{params :params}
{:body params}))
(def app
(-> (handler/api app-routes)
(wrap-json-params)
(wrap-json-response)))
它只是返回:{}
我做错了什么?
最佳答案
我是个白痴,意识到我没有发送 json Content-Type header 。希望没有其他人犯同样的愚蠢错误 :P
关于clojure - 使用 ring format-params 中间件访问发布的 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150297/