PUT时渲染资源

时间:2015-09-25 00:49:04

标签: clojure liberator

我正在使用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"(例如)?

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类似。