May 2015
Intermediate to advanced
274 pages
5h 11m
English
An Action in Play defines how a server should respond to a request. The methods, which define an Action, are mapped to a request in the routes file. For example, let's define an Action which displays the information of all the artists as a response:
def listArtist = Action {
Ok(views.html.home(Artist.fetch))
}Now, to use this Action, we should map it to a request in the routes file.
GET /api/artist controllers.Application.listArtist
In this example, we fetch all the artists and send them with the view, as the response to the request.
The term api used in the route file is just a URL prefix and is not mandatory.
Run the application and access http://localhost:9000/api/artist from the browser. A table with the available artist is visible. ...
Read now
Unlock full access