2

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})))
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76

1 Answers1

3

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

Piotrek Bzdyl
  • 12,965
  • 1
  • 31
  • 49
  • Thank you.What is respond with entity? – Ertuğrul Çetin May 22 '16 at 17:49
  • 2
    Take a look at [liberator decisions](https://clojure-liberator.github.io/liberator/doc/decisions.html). `:respond-with-entity` means that the modified/deleted resource entity should be returned in the response (e.g. `POST /user` as a result will return the created user entity in the response body). – Piotrek Bzdyl May 22 '16 at 18:47