clojureliberator

Render resource when PUT


I am using liberator to build a API using Clojure. Given the follow code:

(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)

Someone when can tell me if is possible, like the GET request, when I send a PUT request it be redirected to the resource ? "/customer/1" (for example) ?


Solution

  • Looking at the liberator decision graph, :put! can lead to either:

    Try implementing :put! so it stores the entity as ::entry, and :handle-created similar to your current :handle-ok.