You are here

Playing with Play - 2

playMain concepts (for Scala)

Keypoints of Main concepts for Scala page.

HTTP programming

An Action handles a Request and generates a Result.

A Controller is an object that generates Action values.

The built-in router translates each incoming request to an Action. Routes are defined in conf/routes. Each route is defined by three parts:

  • HTTP method
  • URI pattern
  • call definition

URI can be static or dynamic. A part of the URI can be passed as a parameter to the call. A parameter may have a default value, or may be optional.

An Action is defined with a type parameter: an Action[A] uses a BodyParser[A] to retrieve a value of type A from the HTTP request, and to build a Request[A] object that is passed to the action code. Built in body parsers are available for JSON, XML, forms, strings, bytes, etc.

Asynchronous HTTP programming

Play framework is asynchronous. Action code must be non-blocking. Consequently, action code should return a Future[Result], instead of returning a Result. Understanding Play thread pools explains how actions are handled.

To be continued...

Previous article