In my application I need to pass a List[String]
to WS API using the GET
method. I tried using withQueryString
, but I'm not able to pass the queryString
data. How to pass list data to controller? How it process the data?
Asked
Active
Viewed 485 times
0

marcospereira
- 12,045
- 3
- 46
- 52

Kiran Sunkari
- 301
- 1
- 3
- 15
-
What are you trying to do? A HTTP request to a third party service or are you trying to receive more than a `List[String]` at your controller? Can you show us (maybe using [`curl`](https://curl.haxx.se/)) how the GET request looks like? – marcospereira May 06 '16 at 19:59
-
i need to receive List[String] in My controller Not to the Thirdparty api services – Kiran Sunkari May 06 '16 at 20:04
-
1See http://stackoverflow.com/questions/35814866/have-a-list-in-play-framework-web-service-parameters and http://stackoverflow.com/questions/37031630/scala-play-squeryl-retrieve-multiple-params/37040324#37040324. – marcospereira May 06 '16 at 20:12
1 Answers
0
If I deciphered the question correctly, you want to receive a List[String]
in your controller, like:
GET /route MyController.someMethod(ids: List[String])
and call it from other app, via WS call, like:
val ids = List("1", "3", "99")
val idsTuples = ids map (id => "ids" -> id)
ws.url(url).withQueryString(idsTuples: _*).get()
See also this.
You can also add more parameters before the idsTuples: _*
, or just add (String, String)
tuples to the idsTuples
...
EDIT: I wrote the first version from my memory, which wasn't correct... :)

insan-e
- 3,883
- 3
- 18
- 43
-
i already tried this but it is throwing an error in querystring statement that it requires Seq(string,string) not Seq(string,list[string]) – Kiran Sunkari May 07 '16 at 04:43
-
I fixed it now, yes, you need to pass varargs of type(s) `(String, String)`, so if you have a `List[(String, String)]` you can pass it like varargs using `: _*` magic. – insan-e May 07 '16 at 14:28