Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get repeating request parameters in Compojure

I can get to the request parameters easily with:

(:foo params)

However, when I have a request like this:

/api?foo=1&foo=2&foo=3

I only get back "3" while I would expect an array ["1","2","3"].

I'm not sure why this is happening because when I look at the code in:

https://github.com/ring-clojure/ring-codec/blob/master/src/ring/util/codec.clj#L128

It seems to call assoc-conj which is supposed to turn multiple params of the same name into a vector containing the values.

Am I missing something here or is this a bug?

like image 579
Stefan Arentz Avatar asked Mar 26 '13 11:03

Stefan Arentz


1 Answers

use a standard Clojure destructuring form:

(GET "/api" {{:strs [foo]} :query-params} (str foo))

curl "http://localhost:3000/api?foo=1&foo=2&foo=3" 
==> ["1" "2" "3"]

doc: https://github.com/weavejester/compojure/wiki/Destructuring-Syntax

like image 186
number23_cn Avatar answered Oct 06 '22 23:10

number23_cn