Please advice, how I can have body read and parsed routes + handler
[""
[["/optimize"
(yada/resource
{:produces "application/json"
:consumes "application/json"
:methods {:post {:response (fn [{:keys [body] :as ctx}]
(prn :B body)
;; (prn :B (-> ctx (get-in [:request :body]) slurp))
(let [params (->> body
(map (fn [[k v]]
[(str k) v]))
(into {}))]
(core/optimize optimizer params)))}}})]]]
and tests
(let [routes (:routes http)
body (cheshire/generate-string {"key" {}})]
(response-for routes :post "/optimize" {:headers {"Content-Type" "application/json"
"Accept" "application/json"}
:body body)
=> {:status 200,
:headers
{"content-length" "2",
"content-type" "application/json"},
:body "OK"})
currently body
in hanlder is nil
[:request :body]
is
:body (#object[java.nio.HeapByteBuffer 0x211c0729 "java.nio.HeapByteBuffer[pos=0 lim=14 cap=4096]"])
Use byte-streams to convert to a string
thanks, will give it a try
the problem is - everything works as expected if I send via curl, but not working for response-for
is there a way to have consistent behaviour?
Aleph streams the HeapByteBuffer to the http browser, response-for bypasses aleph so the behaviour can't exactly match.
clear, thanks!
@kirill.salykin note that there is a with-aleph macro in the test code of yada that you could use
@kirill.salykin https://github.com/juxt/yada/blob/ba10db43e1a332f0bfd352cd8ea39f176190c4ff/src/yada/test.clj#L40
is this replacement for response-for?
yes, I wrote it because of a similar problem
awesome, thanks!
do you have an example how it suppose to be used?
what is resource
in this case?
a yada resource
if you grep for with-aleph in the yada source, you'll find some examples
thanks
just found it as well, thanks!