Reputation: 274
So I have a routes file that calls a controller with several optional inputs. as per below
GET /1.0/*path/documents
controllers.DocumentController.list(path, format: Option[String], ref: Option[String], build: Option[String], files: Option[String], token: Option[String])
I'm looking to customize a URI that would pass defined or provided values for these options, specifically I'm looking to pass :ref & :build from the URI into their respective options below without changing the underlying controller or model calls.
GET /1.0/*path/documents/:ref.:build
controllers.DocumentController.list(path, format: Option[String], Some(ref), Some(build), files: Option[String], token: Option[String])
Currently the above gives this error.
')' expected but '(' found.
I've been using scala for ~3 weeks and have little formal training in OO or MVC development so please go easy on me :)
SOLUTION: Method must be defined to take these parameters as part of a function method rather than as options. see answer below.
Upvotes: 1
Views: 371
Reputation: 274
Optional arguments can only be provided with the query option after the URL. Take for example the below route:
GET /1.0/*path/documents
controllers.DocumentController.list(path, format: Option[String], Option[ref], Option[build], files: Option[String], token: Option[String])
These parameters can be provided by using a query appended to the URI after ?
.
For example:
http://localhost:9000/1.0/pathvariable/documents?format=json&ref=master
If the desired customized route is:
GET /1.0/*path/documents/:ref.:build
Then the ref
and build
variables should not be defined as options but as regular input parameters that must be provided.
Below example where list 2 is a new method taking the 3 parameters as well as some optional parameters:
GET /1.0/*path/documents/:ref.:build
controllers.DocumentController.list2(path, ref: String, build: String, format: Option[String], files: Option[String], token: Option[String])
Upvotes: 1
Reputation: 6462
I don't have the same compilation error than you when testing, but
1. I think that the dot after the :ref
is not authorized and should be a slash.
2. If you want to use an option, specify it like this:
GET /path controllers.DocumentController.list(format: Option[String])
And call it like this:
/path?format=myString
Upvotes: 1