Book Image

Mastering play framework for scala

By : Shiti Saxena
Book Image

Mastering play framework for scala

By: Shiti Saxena

Overview of this book

Table of Contents (21 chapters)
Mastering Play Framework for Scala
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with Play
Index

Configuring request parameters


Many applications use additional parameters along with RESTful HTTP GET requests to obtain required information. Play supports configuring these request parameters as well.

Supposing we have a request to search users by their name, we could define this as follows:

GET           /api/search/user    controllers.UserController.search(name)

Therefore, we wouldn't need to get the parameters from the request in the action. We could let Play handle acquiring the parameters from the request and passing them to the action.

What do we do when the request parameters are optional? For example, what happens if we allow a search of users by their name where lastName is optional.

We can specify Option as the type for this request parameter. Therefore, the route definition would be similar to the following:

GET           /api/search/user    controllers.UserController.search(firstName:String, lastName:Option[String])

In addition to this, we can also specify the default value, if any...