Fork me on GitHub
#ring
<
2021-03-21
>
fullNameHere03:03:27

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

robertfw03:03:25

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

robertfw03:03:31

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

fullNameHere03:03:36

Thank you, ill read into it some more.

robertfw03:03:53

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

👍 3