0

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?

Anton Harald
  • 5,772
  • 4
  • 27
  • 61
  • 1
    Typo in the client code- :response-format? – Jonah Benton Sep 25 '16 at 19:19
  • "10.4.1 400 Bad Request. The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications." That's the reason for nothing in the `prn` call – Brandon Henry Sep 26 '16 at 00:07
  • @jonah thanks for the typo hint. however, the problem was solved by omitting wrap-transit-params in the server code. – Anton Harald Sep 26 '16 at 15:08

0 Answers0