我正在使用liberator使用Clojure构建API。鉴于以下代码:
(defresource single-customer [id]
:allowed-methods [:get, :put]
:exists? (fn [_]
(let [e (get @cust/customers (keyword id))]
(if-not (nil? e)
{::entry e})))
:existed? (fn [_] (nil? (get @cust/customers (keyword id) ::sentinel)))
:available-media-types ["application/json"]
:can-put-to-missing? false
:put! (fn [q] (cust/set-as-fraudulent id))
:handle-ok ::entry)
有人什么时候可以告诉我是否可能,比如GET请求,当我发送PUT请求时,它会被重定向到资源? "/customer/1"
(例如)?
答案 0 :(得分:2)
查看liberator decision graph,:put!
可以导致:
:handle-created
(如果:new?
):handle-no-content
(如果不是:new?
而非:respond-with-entity?
):handle-ok
(如果不是:new
,但是:respond-with-entity?
)尝试实施:put!
,以便将实体存储为::entry
,将:handle-created
存储为与您当前的:handle-ok
类似。