This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-20
Channels
- # announcements (3)
- # beginners (63)
- # calva (1)
- # cider (24)
- # clj-kondo (98)
- # cljdoc (8)
- # cljsrn (19)
- # clojure (106)
- # clojure-conj (2)
- # clojure-europe (5)
- # clojure-italy (5)
- # clojure-nl (8)
- # clojure-spec (8)
- # clojure-uk (13)
- # clojuredesign-podcast (7)
- # clojurescript (54)
- # core-async (1)
- # cursive (3)
- # data-science (1)
- # datomic (19)
- # fulcro (7)
- # hoplon (1)
- # off-topic (3)
- # re-frame (13)
- # reitit (1)
- # shadow-cljs (234)
- # test-check (10)
- # tools-deps (59)
- # unrepl (1)
- # yada (20)
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
is this replacement for response-for?
awesome, thanks!
do you have an example how it suppose to be used?
what is resource
in this case?
thanks
just found it as well, thanks!