【发布时间】:2018-08-28 09:26:49
【问题描述】:
我是 Clojure webdev 生态系统的新手,我想使用 liberator API 使用 POST 方法发送 JSON 响应,我试过这个:
(POST "/post/savecomment"
request
(resource
:allowed-methods [:post]
:available-media-types ["application/json"]
:handle-ok (fn [ctx]
(format (str "{body: %s a: 1 b: 4}"), "the body part"))))
一切正常,没有错误消息,我从 ring 收到“201 Created”响应,但未发送 JSON 数据,Chrome 中的“响应”选项卡为空。需要我添加一些东西吗?顺便说一句,我使用的是 compojure,而不是 compojure-api。
我也试过了:
(POST "/post/savecomment" request (resource
:allowed-methods [:post]
:available-media-types ["application/json"]
:available-charsets ["utf-8"]
:handle-ok (fn [_] (rep/ring-response {:status 200 :body "\"this is json\""}))
:post! (fn [ctx] (rep/ring-response {:status 666 :body "\"this is json\""}))
))
但没有运气。
【问题讨论】:
-
你能检查这个链接吗:clojure-liberator.github.io/liberator/tutorial/post-et-al.html 我也看不到你的帖子!功能
-
刚起步,现在可能是比较Ring、liberator和Yada的方法的好时机:github.com/juxt/yada/blob/master/dev/resources/…
标签: clojure compojure liberator