1
votes

I am trying to get my head round clojure liberator and i have come across this type of code below:

  :handle-ok (by-method {
    :get (fn [ctx] (render-item (:item ctx)))
    :post (fn [ctx] (render-item (:item ctx)))
    :put (fn [ctx] (update-item-response coll-slug ctx))})

At first I thought that handle-ok was simply for GET requests but then I came across this.

Why would I provide handlers for post and put in the example above? Are these post-request handlers.

1

1 Answers

2
votes

Take a look at the decision graph, at the bottom where you see the resulting code 200. Hovering over it will show you that this is actually where :handle-ok comes into play. And a status code of 200 can be the result of many different paths through the decision graph, including put and post.