In short, you have many options ... all are slightly different from each other. You can use the following URL formats:
/foo/bar?color=red&color=blue/foo/bar?color=red,blue/foo/bar?color=[red,blue]/foo/bar?color[]=red,blue
You can:
1. Use forms of reproduction
Simple configuration:
// form definition case class ColorParams(colors:Seq[String]) val myForm = Form(formMapping( "color" -> seq(text(1, 32)))(ColorParams.apply)(ColorParams.unapply) // in your controller method call val params = myForm.bindFromRequest()
Example URL: /foo/bar?color[]=red,blue will become List("red","blue")
Unfortunately, this is not so reliable, as many APIs use the format color=red,blue or color=red&color=blue
2. Create your own custom string parser
In more detail, but you can write restrictions, tests, and leave everything on the router. Pro is that invalid requests never reach your controller.
Then you just use it in your routes file, for example:
case class ColorParams(colors:List[MyColorEnum])
GET /foo/bar? controllers.Example.getBar(color:ColorParams)
Example URL: /foo/bar?color=red,blue
Since you are parsing the string yourself, you can use any string layout in this post using this method. See QueryStringBindable for more details. I will add a complete example later.
3. Define your array parameter in the routes file
GET /foo/bar? controllers.Example.getBar(color:Seq[String])
// inside Example.scala def getBar( colors:Seq[String] ) = { ??? }
Example URL: /foo/bar?color=red&color=blue
Note. For clarity, I used color in the routes file, which is the name in the URL, but colors in the getBar method. These names should not match, only types.
Gotchas
Please note that this can be difficult, because /foo/bar?color=red,blue becomes Seq ("red, blue"), this is Seq of one line, not two lines, but it will still be displayed in the debugger as Seq(red,blue) . The correct value that you need to see in the debugger will be Seq(red, blue) , pay attention to this space? Tricky.