clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
2020-03-19T13:17:10.116Z

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.

2020-03-19T13:44:59.116100Z

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))

2020-03-19T13:45:41.116300Z

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.

nate 2020-03-19T15:28:44.116600Z

ah interesting

nate 2020-03-19T15:29:14.116800Z

glad you figured it out

nate 2020-03-19T15:29:33.117Z

testing would be a good topic, indeed