joesan
joesan

Reputation: 15345

Play Framework Error in Routes file

I have the following route that takes in an optional set of parameters:

GET  /data  com.controllers.MyController.data(ids: Option[Seq[Long]])

When I compile the project, I get the following error:

[warn]  ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[error] (compile:managedSources) @6plhijkoi: Compilation error in /Users/joe/projects/my-project/conf/routes:26
[error] Total time: 5 s, completed Apr 12, 2016 12:03:55 PM

Line number 26 in my routes file is exactly what I have posted above. Any ideas as to why this error occurs? Is it not possible to have an optional Seq of parameters? The goal is to have one route for the following:

localhost:9000/data           - should fetch all the data
localhost:9000/data?id=1&id=2 - should fetch data with id 1 and 2
localhost:9000/data?id=1      - should fetch data with id 1

Any suggestions?

Upvotes: 3

Views: 382

Answers (2)

joesan
joesan

Reputation: 15345

I figured out what the problem is and here is how I managed to get it work:

GET  /data  com.controllers.MyController.data(ids: List[Long])

Notice the datatype, I changed the type from Seq to List and I did not need the Option. So the calls would become:

/data?ids=1&ids=2 - filters based on id 1 and 2
/data             - gets me all the data 

Upvotes: 1

airudah
airudah

Reputation: 1179

It might not know how to handle an Option[Seq[Long]]

You could have a router as such:

GET /data com.controllers.MyController.data(id1: Option[Long], id2: Option[Long])

Then handle None values in your controller.

Upvotes: 0

Related Questions