Optional query parameters do not work as expected
Closed this issue ยท 1 comments
jroylance commented
Routes with optional query parameters return a 400 response when the query parameter is not provided. Below is a minimal repro example:
package app
import scala.annotation.nowarn
@nowarn
object MinimalApplication extends cask.MainRoutes {
@cask.get("/")
def hello(param: Option[String]) = {
"Hello World!"
}
initialize()
}
I ran this application and then ran the following in my terminal:
$ curl http://localhost:8080?param=asdf
Hello World!
$ curl http://localhost:8080
Missing argument: (param: Option[String])
Arguments provided did not match expected signature:
hello
param Option[String]
The expected behavior is that both curl
requests succeed.
jroylance commented
Found a workaround, or perhaps the intended way of using optional query parameters - by using a default of None:
package app
import scala.annotation.nowarn
@nowarn
object MinimalApplication extends cask.MainRoutes {
@cask.get("/")
def hello(param: Option[String] = None) = {
"Hello World!"
}
initialize()
}
This solves my problem, and apologies for the spam