ring

2021-03-21T03:09:27.000200Z

Hey guys, i've been trying to understand ring-clojure lib. I was reading the through the examples and ran into the form parameters one. (defn page [name] (str "<html><body>" (if name (str "Nice to meet you, " name "!") (str "<form>" "Name: <input name='name' type='text'>" "<input type='submit'>" "</form>" "</body></html>")))) (defn handler [{{name "name"} :params}] (-> (response (page name)) (content-type "text/html"))) (def app (-> handler wrap-params)) (run-jetty app {:port 8080}) Im guessing this is mostly a clojure itself question opposed to a ring one, but I dont really know what [{{name "name"} :params}] is doing. Could anyone explain? Thanks in advance!!

robertfw 2021-03-21T03:25:25.000300Z

@santosx99xx that's associative destructuring, which you can read about here https://clojure.org/guides/destructuring

robertfw 2021-03-21T03:26:31.000500Z

in this case you're having a map passed in, which will have a value under the :params key, which itself will be a map with a value under the "name" key, which is being bound to name

2021-03-21T03:27:36.000700Z

Thank you, ill read into it some more.

robertfw 2021-03-21T03:30:53.000900Z

happy to help. if you run into more questions with destructuring pop a question in #beginners, there'll be more people responding there

👍 1