The ClojureScript cljs-ajax client library converts {:b [1 2]}
to b[0]=1&b[1]=2
For example:
(http/get "http://example.com" {:b [1 2]})
results in a request to:
"http://example.com?b[0]=1&b[1]=2"
How can I setup my ring middleware to handle this format on the server side? I would like to convert it back to the original structure:
{:b [1 2]}
I am using the middleware below, but it does not work properly:
(ring.middleware.keyword-params/wrap-keyword-params)
(ring.middleware.params/wrap-params :encoding encoding)
(ring.middleware.nested-params/wrap-nested-params)
There is no issue in middleware side. The issue is in cljs-ajax's ajax.core/params-to-str
api. It is generating duplicate URL for different data format.
(ajax.core/params-to-str {:b [1 3]})
;; => "b[0]=1&b[1]=3"
(ajax.core/params-to-str {:b {0 1 1 3}})
;; => "b[0]=1&b[1]=3"
For array, format should be b[]=1&b[]=3
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With