Fork me on GitHub
#clojuredesign-podcast
<
2020-03-19
>
markbastian13:03:10

Ok, here's a fun one that I'm hoping anyone here can help me with:

(require '[ring.middleware.params :refer [wrap-params]])
(require '[ring.mock.request :as mock])

(let [fake-handler (wrap-params identity)
      request (mock/request :get "/foo" {:query-params {:x [1 2 3]}})]
  (fake-handler request))
The result is:
{:protocol "HTTP/1.1",
 :remote-addr "127.0.0.1",
 :params {"query-params" "x=1", "x" ["2" "3"]},
 :headers {"host" "localhost"},
 :server-port 80,
 :form-params {},
 :query-params {"query-params" "x=1", "x" ["2" "3"]},
 :uri "/foo",
 :server-name "localhost",
 :query-string "query-params=x=1&x=2&x=3",
 :scheme :http,
 :request-method :get}
I'm a bit stumped as to why the params are decoded as they are. Any insight would be great as well as any tips on the right way to get the original x vector recovered in the params.

markbastian13:03:59

Figured it out. I am adding the params incorrectly. Should be:

(require '[ring.middleware.params :refer [wrap-params]])
(require '[ring.mock.request :as mock])

(let [fake-handler (wrap-params identity)
      request (mock/request :get "/foo" {:x [1 2 3]})]
  (fake-handler request))

markbastian13:03:41

BTW, ring-mock would be a good topic. For example, I don't see great docs on how to specify form params, body params, etc.

nate15:03:44

ah interesting

nate15:03:14

glad you figured it out

nate15:03:33

testing would be a good topic, indeed