1

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

4

1 回答 1

2

查看解放者决策图:put!可能导致:

  • :handle-created(如果:new?
  • :handle-no-content(如果不是:new?和不是:respond-with-entity?
  • :handle-ok(如果不是:new,但是:respond-with-entity?

尝试实现:put!,以便将实体存储为::entry,并且:handle-created类似于您当前的:handle-ok.

于 2015-09-26T13:30:29.807 回答