2015-09-25 110 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