On 2 авг, 04:47, Brad wrote:
> I wanted to take a Map and convert it to a string suitable for use as
> parameters in a URL. I have got it working below two different ways
> but wondered if there was a better or more idiomatic way to do this.
>
> ;; My test input map
> (def input {:a 1 :b 2 :c 3
Great. Encoding the parameters was the next thing to figure out.
Thank you.
On Aug 2, 12:51 am, Matjaz Gregoric wrote:
> Depending on your input, you might also want to make sure to properly
> urlencode the keys and values.
> There is a function in hiccup that does what you want (including
> urle
Thanks. This is much more succinct.
On Aug 2, 12:19 am, Sean Corfield wrote:
> On Mon, Aug 1, 2011 at 3:47 PM, Brad wrote:
> > ;; My test input map
> > (def input {:a 1 :b 2 :c 3 :d 4})
> ...
> > Is there a simpler, better way to do this?
>
> How about:
>
> (require '[clojure.string :as str])
>
Depending on your input, you might also want to make sure to properly
urlencode the keys and values.
There is a function in hiccup that does what you want (including
urlencoding):
https://github.com/weavejester/hiccup/blob/10c3ebe175edc80eed1a0792ec68036be47940d3/src/hiccup/page_helpers.clj#L117-1
On Mon, Aug 1, 2011 at 3:47 PM, Brad wrote:
> ;; My test input map
> (def input {:a 1 :b 2 :c 3 :d 4})
...
> Is there a simpler, better way to do this?
How about:
(require '[clojure.string :as str])
(defn map-to-query-string [m]
(str/join "&" (map (fn [[k v]] (str (name k) "=" v)) m)))
--
Se
I wanted to take a Map and convert it to a string suitable for use as
parameters in a URL. I have got it working below two different ways
but wondered if there was a better or more idiomatic way to do this.
;; My test input map
(def input {:a 1 :b 2 :c 3 :d 4})
;; What I'd like the input map conv