simpleui
simpleui copied to clipboard
Document that parameters need to be keywordized
I integrated ctmx into a template stack I use that runs pedestal+reitit. Out of the box any ctmx components relying on POST params were not working. The root issue was that the form parameters were not being convert to keywords. reitit.http.interceptors
doesn't include an interceptor out of the box for this. reitit.http.interceptors.parameters
only keywordizes query params.
The solution is to use the ring keyword-params middleware and wrap it in an interceptor:
(ns foo (:require
[reitit.http.interceptors.parameters :as parameters]
[ring.middleware.keyword-params :as keyword-params]))
(def keyword-params-interceptor
{:name ::keyword-params
:enter (fn [ctx]
(let [request (:request ctx)]
(assoc ctx :request
(keyword-params/keyword-params-request request))))})
(def default-interceptors [
;; add other interceptors as you see fit
(parameters/parameters-interceptor)
keyword-params-interceptor])
; use default-interceptors in your routes
For ctmx it might be useful to mention in the docs/readme that the library expects all parameters to be keywordized.
Thanks @Ramblurr ! I'll make sure to do that. Will you publish the template stack to e.g. clojars?
I can't publish the template stack as is because it's internal (it has a lot of other non ctmx related stuff), but I can create a sample project showing pedestal + reitit.http.interceptors + ctmx!
@Ramblurr please publish that and I will update my doco and make any other changes as necessary. Your help is much appreciated!
Hi @Ramblurr , any luck reproducing the issue for me in a public repo? I would like to fix this issue but its good to confirm with a demo to nail down that we are talking about the same thing.
Sorry for the delay!
Here is a sample repo: https://github.com/Ramblurr/ctmx-pedestal/blob/main/src/ctmx_pedestal/demo.clj
Just jump into the repl, load the demo ns, then run the start fn. You can see the commented bits about the keyword-params-interceptor
that relate to this issue.
@Ramblurr I've added a note to README.md in the introduction. Are there any other changes you'd like to see?
Looks good to me! Maybe link to this issue for more context?