I'm looking for a way to conveniently exchange Clojure data structures between a ClojureScript browser client and a Clojure server.
Currently I'm using cljs-ajax for the front-end and ring/compojure + transit-middleware on the back-end.
Until now, I only got the server responses working this way. However, here's a round-trip code, which at the moment makes some trouble:
client:
(def data {:nested #{(rand-int 1000)}})
(POST "/round" {:params data
:response-format :transit
:format :transit
:handler #(js/alert (= data %))}))
and here's the relevant server code:
(defroutes main-routes
(POST "/round" {p :params} (do (prn p)
(response p))))
(def app
(-> main-routes
(wrap-transit-body {:keywords? true})
(wrap-transit-response)
(wrap-transit-params)))
I was expecting this server code to echo back the data structure. The browser developer tools reveal that the server response is actually 400 and this plain text: "Malformed Transit in request body." At the server side nothing gets ever logged by the prn
function in the route.
Does anybody know how to fix this?