ABOUT THIS BOOK
xvii
more. We expect that the reader has a basic understanding of the web in general and
HTTP and HTML in particular.
This isn’t a book about learning Scala, although we understand that Scala is likely
new to many readers as well. We recommend picking up this book after an introduc-
tion to Scala, or in parallel with an introduction to Scala. Though we stay clear of the
hard parts of Scala, some of the language constructs will likely be hard to grasp for
readers who are entirely unfamiliar with Scala.
This book isn’t the one book about Play that covers everything. Partly, this is
because Play is a new framework and is evolving rapidly. Best practices are often not
worked out yet by the Play community. There’s also a more mundane reason: page
count. The subject of testing, for example, didn’t fit within the page limit for the
book, and rather than doing a very condensed chapter about testing, we chose to
leave it out.
If you’re curious, the short version is that Play is highly testable. This is partly due
to its stateless API and functional style, which make the components easier to test. In
addition, there are built-in testing helpers that let you mock the Play runtime and
check the results of executing controller actions and rendering templates without
using HTTP, plus FluentLenium integration for user-interface level tests.
Rather than trying to cover everything, this book tries to lay a foundation, and we
hope that many more books about Play will be written. There’s much to explore
within Play and on the boundaries between Play and the Scala language.
Roadmap
Chapter 1 introduces the Play framework, its origins, and its key features. We look at how
to get started with Play, and glance over the components of every Play application.
Chapter 2 shows in more detail the components of a Play application and how they
relate to each other. We build a full application with all the layers of a Play application,
with multiple pages, and with validation of user input.
Chapter 3 starts with a dive into the architecture of Play. We show why Play works
so well with the web, and how control flows through your application. We look at how
the models, views, and controllers of an application fit together and how an applica-
tion can be modularized.
Chapter 4 focuses on controllers. Controllers form the boundary between HTTP
and Play. We see how to configure a Play application’s URLs, and how to deal with URL
and query string parameters in a type-safe way. We use Play forms to validate and
retrieve user input from HTML forms, and we learn how to return an HTTP response
to the client.
Chapter 5 shows how a persistence layer fits into a Play application. Anorm is a
data access layer for SQL databases that’s bundled with Play and works with plain SQL.
As a possible alternative, we also introduce Squeryl, which is a data access layer that
uses a Scala domain-specific language to query a database.