clojurelispclojurescriptringliberator

Post Does Not Return 200 OK in Liberator Clojure


I want my POST resource to return 200 OK so I can use :handle-ok but resource returns 201 Created.

I use my resource for the login operation. :handle-ok does not work!

Here is the example code:

(POST "/login" []
             (resource :allowed-methods [:post]
                       :available-media-types resource-util/avaliable-media-types
                       :known-content-type? #(resource-util/check-content-type % resource-util/avaliable-media-types)
                       :malformed? #(resource-util/parse-json % ::data)
                       :post! (fn [ctx]
                                {:my-data "oki"})
                       :handle-ok (fn [ctx]
                                    {:ok? true})))

Solution

  • You need to add :new? false :respond-with-entity? true to your resource definition. Check out more details in the decision graph. You should also return a value that will be the body of the response (as you want to return HTTP 200, if you have no value to be returned HTTP 204 is more appropriate).