scala - How to handle optional query parameters in Play framework -


lets have functioning play 2.0 framework based application in scala serves url such as:

http://localhost:9000/birthdays

which responds listing of known birthdays

i want enhance adding ability restrict results optional "from" (date) , "to" request params such as

http://localhost:9000/birthdays?from=20120131&to=20120229

(dates here interpreted yyyymmdd)

my question how handle request param binding , interpretation in play 2.0 scala, given both of these params should optional.

should these parameters somehow expressed in "routes" specification? alternatively, should responding controller method pick apart params request object somehow? there way this?

encode optional parameters option[string] (or option[java.util.date], you’ll have implement own querystringbindable[date]):

def birthdays(from: option[string], to: option[string]) = action {   // … } 

and declare following route:

get   /birthday       controllers.application.birthday(from: option[string], to: option[string]) 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -