Book Image

Play Framework essentials

By : Julien Richard-Foy
Book Image

Play Framework essentials

By: Julien Richard-Foy

Overview of this book

Table of Contents (14 chapters)
Play Framework Essentials
About the Author
About the Reviewers


The Web allows you to make applications that can be used from anywhere in the world as long as there is an Internet connection. The Play framework has been designed to embrace the characteristics of modern web applications such as handling long-running requests and manipulating data streams.

This book shows you how to write such web applications using Play. I designed it to be progressive so that you can quickly write a running application and then enhance it to benefit from all the components of the Play stack, or from lower-level APIs if you need more control.

Code examples are given in both Scala 2.10 and Java 8 (except for some APIs that have no Java counterpart). You can find executable applications based on the code examples of the book at

Finally, I encourage you to browse the API documentation of the framework to complete the content of this book. You can find it online at

What this book covers

Chapter 1, Building a Web Service, explains how to turn an application into a web service by exposing its resources and features as HTTP endpoints.

Chapter 2, Persisting Data and Testing, shows how you can integrate a persistence system to your Play application and how to write specifications of your HTTP layer.

Chapter 3, Turning a Web Service into a Web Application, goes one step further by showing you how the Play framework can help you to define HTML pages for your application and handle HTML forms.

Chapter 4, Integrating with Client-side Technologies, gives you insights on ways to manage the production of web assets from the build system of your Play application.

Chapter 5, Reactively Handling Long-running Requests, dives deeper in the framework internals and explains how to leverage its reactive programming model to manipulate data streams.

Chapter 6, Leveraging the Play Stack – Security, Internationalization, Cache, and the HTTP Client, presents additional components that are part of the Play stack.

Chapter 7, Scaling Your Codebase and Deploying Your Application, looks back at the code of your application and provides patterns to keep it modular and easy to maintain. It also explains how to deploy your application in a production environment.

What you need for this book

The content of this book is based on Play 2.3.x and shows both Scala and Java APIs. Though this book uses Java 8, Play supports Java 6, so all you need to start developing a Play application is at least JDK 6. Chapter 1, Building a Web Service, explains how to install activator, a command-line tool to generate starter application skeletons and then manage their life cycle (running, testing, and so on). Finally, you also need a web browser to use your applications.

Who this book is for

This book targets Java or Scala developers who already have some knowledge of web development.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Source files are under the app/ directory."

A block of code is set as follows:

val index = Action {
  Ok("Just Play Scala")

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

val index = Action {
  Ok("Just Play Scala")

Any command-line input or output is written as follows:

$ curl -v http://localhost:9000/items

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "If everything works fine, your browser should show a page titled Just Play Scala (or Just Play Java)."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.