2015-09-25 83 views
1

我正在使用liberator使用Clojure构建API。鉴于后续代码:PUT时渲染资源

(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"(例如)?

回答

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

+0

谢谢@xsc,下次我会检查决定图:) – elf