I have one defresource, that is supposed to take POST-requests, validate request body in :malformed-decision, save the body to database in :post!-decision and return the saved body in :handle-created.
(defn parse-project [context] (json/read-str
(slurp (get-in context [:request :body]))
:key-fn keyword))
(defresource add-new-project
:malformed? (fn[ctx] (not (project-is-valid (parse-project ctx))))
:handle-malformed (fn [_] (generate-string (str "Malformed json!")))
...
:post! (fn [ctx] (save-to-db (parse-project ctx))
:handle-created (fn [ctx] (... parse-project ...))
So my code reads three times the ByteArrayInputStream(that comes from :request :body) with slurp-function. First time works but second time when slurp is called, nil is passed as a param and comes java.io.EOFException: JSON error. I think the reader starts reading where it was left last time.
How could I read the body of the request three times? Or is there nice way to save the result of reading to variable and pass that to other liberator-decisions?