4
votes

In my web handler, I have the following defined:

(:require ... 

[ring.middleware.cookies :refer [wrap-cookies]]
            [ring.middleware.multipart-params :refer [wrap-multipart-params]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.middleware.keyword-params :refer [wrap-keyword-params]]
            [ring.middleware.content-type :refer [wrap-content-type]]
            [ring.middleware.format-response :refer [wrap-restful-response]
...)

(def app
  (-> (routes home/my-routes)
      (wrap-cookies)
      (wrap-params)
      (wrap-multipart-params)
      (wrap-keyword-params))))

Everything works. Testing with curl using a URL that looks like "../test?foo=123" gives me a params map that looks like {:foo 123}. However, what appears as a keyword is actually a string: (keyword? :foo) returns false.

I've tried rearranging the handlers and removing them one at a time, but to no avail. Is there something about compojure that is converting the keywords back into strings? Thanks

1
Did you mean: (keyword? ":foo")?Jeremy
No: I did this: (println "is keyword " (keyword? (key (first params))))pickwick

1 Answers

6
votes

wrap-keyword-params middleware should be run after wrap-params and wrap-multipart-params, so your app should look like:

(def app
  (-> (routes home/my-routes)
      (wrap-keyword-params)
      (wrap-cookies)
      (wrap-params)
      (wrap-multipart-params))))