大约10多年前,我稍微涉猎了一下clojure,现在又回到了clojure,所以我可能在这里做了一些愚蠢的事情。
我正试图用它编写一个简单的API
compojure
和
ring
服务器,现在我已经把我的问题隔离到了几行。我有一条路线和一个处理程序,我用
wrap-json-body
原样
suggested
在里面
ring-json
文档
我的
handler.clj
是这样的:
(defroutes app-routes
(PUT "/item/:id" {{id :id} :params body :body} (str id ", " body))
(route/not-found "Not Found"))
(def app
(-> app-routes
(middleware/wrap-json-body)
(middleware/wrap-json-response)))
这应该足够简单,而且我能够以json OK的形式返回clojure数据。问题是当我试图阅读的时候
PUT
请求主体json。
$ curl -XPUT -H "Content-type: application/json" -d '{ "id": 32, "name": "pad" }' 'localhost:3001/item/5'
5, {"id" 32, "name" "pad"}
我想
body
充满
{:id 32 :name "pad"}
以下是整个请求对象:
; (PUT "/item/:id" body (str id body))
$ curl -XPUT -H "Content-type: application/json" -d '{ "id": 32, "name": "pad" }'
{:ssl-client-cert nil, :protocol "HTTP/1.1", :remote-addr "0:0:0:0:0:0:0:1", :params {:id "5"}, :route-params {:id "5"}, :headers {"user-agent" "curl/7.58.0", "host" "localhost:3001", "accept" "*/*", "content-length" "27", "content-type" "application/json"}, :server-port 3001, :content-length 27, :compojure/route [:put "/item/:id"], :content-type "application/json", :character-encoding "UTF-8", :uri "/item/5", :server-name "localhost", :query-string nil, :body {"id" 32, "name" "pad"}, :scheme :http, :request-method :put}
我对它做了一些调整和改变,但我似乎无法得到它
:body
要填充关键字ed clojure数据。
请问我做错了什么?
ps:如果你想看看这个问题的工作示例,我已经上传到了
github