Route URL Pattern for a method signature that takes an optional list of Strings

In my Play 2 controller (Scala) I've a method that looks like the following.

start(id:String, keywords:Option[List[String]]) 

Basically I want to get pass a list of string as keywords where it's optional.

The following doesn't work and gives me a compile error.

GET        /start         start(id:String,options:Option[List[String]])

The error makes sense because even if this route compiled I'm not sure how I would pass a list of Strings in my GET URL.

I'm looking for suggestions to resolve this.

Answers


Since you're just using keywords, how about comma-separated values in the query string?

GET     /start/:id                    controllers.Sample.start(id: String, options: Option[String])

/start/1233?options=key,word,test

Then in your controller convert to Option[List[String]]:

def start(id: String, options: Option[String]) = Action {
    val opts: Option[List[String]] = options.map(_.split(',').filter(_.nonEmpty))

    ...
}

Need Your Help

Can I run a stored lambda whose captured values are no longer in scope?

c++ lambda c++-amp

I have a future to which I want to pass a lambda to run when it is complete, but the scope will have changed by the time the lambda executes; what happens to the captured value? For example

C Programming 2 pipes

c operating-system pipe execvp dup2

I want to set up 2 pipes in my program. I have 1 pipe working fine, but I don't know where to place the second pipe.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.