September 2018
Intermediate to advanced
398 pages
9h 43m
English
First, we need to add the new endpoint to the routes file, as follows:
# Login POST /v1/login controllers.WebServices.login
With this new entry, Play reacts to the POST action and calls the login method of the Webservices class.
The implementation of this login method is as follows:
def login() = Action { request =>
request.body.asText match {
case None => BadRequest
case Some(user) => Ok.withSession("user" -> user)
}
}
If a body with the username is present, the OK status is returned, with a new session cookie. The username is added in the cookie, with the user key, and can be retrieved on a subsequent request.
Run APISpec again; the login test should now be green.
Read now
Unlock full access