biff

Billy 2025-04-16T14:03:42.277669Z

hello! is there some builtin middleware that will keywordize params map for data coming from forms?

2025-04-16T15:03:14.541119Z

yep, this should happen by default. E.g. the starter app has keywordized params here: https://github.com/jacobobryant/biff/blob/1570ccc694c610422d70f4b63eeaa2ba456889ac/starter/src/com/example/app.clj#L16 are they not being keywordized for you?

Billy 2025-04-16T18:47:47.159569Z

for some reason no:

(defn create-comm [{:keys [session params] :as req}]
  (println "params" (pr-str params))
  ...
;; params {:__anti-forgery-token "...", "comm/title" "wertgw", "comm/category" "letter", "comm/content" "etrghrtyj"}

Billy 2025-04-16T18:48:38.620349Z

params are from a biff/form POST, with input field names like "comm/content"

2025-04-16T19:35:25.147039Z

Oh yeah, I think the keywordization only runs for "simple" keys for some reason, not ones with namespaces. I just went spelunking through the middleware and found that this is the middleware which handles the keywordization: https://github.com/ring-clojure/ring/blob/f7dfe7c9b98c335e4573e61d94c523d5df9a6667/ring-core/src/ring/middleware/keyword_params.clj#L37 Given that (and https://github.com/ring-clojure/ring-defaults/blob/52a5b9e50cd64da9d92f84219f8b6240e5500002/src/ring/middleware/defaults.clj#L112), you should be able to update https://github.com/jacobobryant/biff/blob/1570ccc694c610422d70f4b63eeaa2ba456889ac/starter/src/com/example/middleware.clj#L42 to include a (-> rd/site-defaults (assoc-in [:params :keywordize :parse-namespaces?] true) ...) .

🙌 1
Billy 2025-04-16T19:40:01.312759Z

thanks! the rabbit hole isn't that deep when one knows their shit! 😄

🐰 1
😎 1
Billy 2025-04-17T07:44:47.124389Z

if anybody stumbles across, the assoc might fail if keywordize parameter exists and is a bool, this works instead:

(assoc-in [:params :keywordize] {:parse-namespaces? true})

2025-04-17T08:35:18.385349Z

ah yes, that's the way