Reader small image

You're reading from  Mastering play framework for scala

Product typeBook
Published inMay 2015
Reading LevelIntermediate
Publisher
ISBN-139781783983803
Edition1st Edition
Languages
Right arrow
Author (1)
Shiti Saxena
Shiti Saxena
author image
Shiti Saxena

Shiti Saxena is a software engineer with around 4 years of work experience. She is currently working with Imaginea (a business unit of Pramati). She has previously worked with Tata Consultancy Services Ltd. and Genpact. A true polyglot, she's had exposure to various languages, including Scala, JavaScript, Java, Python, Perl, and C. She likes to work with Play Scala and AngularJS. She blogs at http://eraoferrors.blogspot.in and maintains open source projects on GitHub. She loves to travel, is a movie buff, and likes to spend time playing her piano whenever she is not programming. She has authored Getting Started with SBT for Scala (https://www.packtpub.com/application-development/getting-started-sbt-scala).
Read more about Shiti Saxena

Right arrow

Actions


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.

Note

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.

Action takes a request and yields a result. It is an implementation of the EssentialAction trait. It is defined as:

trait EssentialAction extends (RequestHeader => Iteratee[Array[Byte], Result]) with Handler {
 
  def apply() = this

...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering play framework for scala
Published in: May 2015Publisher: ISBN-13: 9781783983803

Author (1)

author image
Shiti Saxena

Shiti Saxena is a software engineer with around 4 years of work experience. She is currently working with Imaginea (a business unit of Pramati). She has previously worked with Tata Consultancy Services Ltd. and Genpact. A true polyglot, she's had exposure to various languages, including Scala, JavaScript, Java, Python, Perl, and C. She likes to work with Play Scala and AngularJS. She blogs at http://eraoferrors.blogspot.in and maintains open source projects on GitHub. She loves to travel, is a movie buff, and likes to spend time playing her piano whenever she is not programming. She has authored Getting Started with SBT for Scala (https://www.packtpub.com/application-development/getting-started-sbt-scala).
Read more about Shiti Saxena