How I can have an API which can be called as http://our.api.com/product/<id1>,<id2>
and receive the list of ids using webnoir ?
Asked
Active
Viewed 632 times
2
-
Don't use comma separated values in URL. Instead use query string to pass the product ids – Ankur May 25 '12 at 10:58
1 Answers
2
(defpage product-view "/product/:ids" {:keys [ids]}
(str (into [] (map #(Integer/parseInt %) (.split ids "-"))))
)
here one parameter (ids) is passed to split by "-", and then each element is parsed as int for url http://our.api.com/product/11-222-3 the output will be [11 222 3]
you can select other separator then "-", but ,.; are not working (i have no time to figure what it is: restriction of ring or smth else)

zmila
- 1,651
- 1
- 11
- 13
-
This is just missing a set of square brackets: `(defpage [:get ["/product/:ids"]] {:keys [ids]} (json (map #(Integer/parseInt %) (.split ids ","))))` You could also add a regex: `(defpage [:get ["/product/:ids" :ids #"\d+(,\d+)*"]] {:keys [ids]} (json (map #(Integer/parseInt %) (.split ids ","))))` – mikebridge May 29 '12 at 04:48
-
@mikebridge, I'm recieving CompilerException java.lang.ClassFormatError: JVMCFRE068 class name is invalid; class=...$GET_LBRACK__DOUBLEQUOTE___product___GT_ids_DOUBLEQUOTE_ _GT_ids _SHARP__DOUBLEQUOTE__BSLASH_d_PLUS_(,_BSLASH_d_PLUS_)_LT__DOUBLEQUOTE__RBRACK_$fn__4617 – zmila May 29 '12 at 08:28
-
-
I ran into the same CompilerException today when I didn't have the regex inside the vector with the route definition. – mikebridge May 30 '12 at 19:11
-