Post Request with clojure liberator

1.1k views Asked by At

I am using clojure liberator to expose my services as REST service,I have a POST request, Below is the code, I could do the process on calling the service as POST, but I want to send back the event id as response of the POST, Can anyone help

(defresource send-event-resource
 :method-allowed? (request-method-in :post)
  :available-media-types ["text/plain"]
  :post! (fn [context]
           (workers/send-event context)))
2

There are 2 answers

0
user1249655 On

Raised an issue in liberator, got the response from there https://github.com/clojure-liberator/liberator/issues/61

0
ordnungswidrig On

Put the event id in to context map and look it up from handle-ok:

(defresource send-event-resource
  :method-allowed? (request-method-in :post)
  :available-media-types ["text/plain"]
  :post! (fn [context] {::event-id (workers/send-event context)})
  :handle-ok ::event-id)

The above code makes use of the fact that a clojure keyword is a function that when applied to the context map will look up "itself".