Documentation

§Play Tutorials

Play’s documentation shows the available features and how to use them, but the documentation will not show how to create an application from start to finish. This is where tutorials and examples come in.

Tutorials and examples are useful for showing a single application at work, especially when it comes to integrating with other systems such as databases or Javascript frameworks.

§Activator Templates Overview

Many tutorials come in the form of templates, which can be downloaded as projects onto your computer.

A full list of templates can be discovered in the Activator Web Interface or by typing “activator list-templates” at the command line.

Templates are also published on the Lightbend website. A full list of both official and community contributed templates for Play can be found here.

Finally, the core Play templates are available as git repositories on Github under https://github.com/playframework/ and can be cloned directly from there.

§Creating a Project From A Template

In general, whenever you see a template, you can download the template by using the Github project name. For example, if you have an example Play project on Github called “some-awesome-play-template”, you can download and use the template by typing

activator new my-local-project-directory some-awesome-play-template 

If you do not have activator installed or would prefer to use git, you can always clone the project the old fashioned way:

git clone https://github.com/playframework/some-awesome-play-template my-local-project-directory

Creating new projects is covered in more detail in Creating a new application.

§Play Maintained Seeds and Example Templates

This section covers the core tutorials and examples from Play. These are maintained by the core Play team, and so will be based on the latest Play release.

§Creating a Seed Template

If you are starting off a new Play project and don’t want any extras, you can use the seed templates by typing the following at the command prompt:

activator new my-scala-project play-scala 

or

activator new my-java-project play-java

If you want to look at the template code without creating a new project, you can see the templates below:

§Database / ORM Access

Play is unopinionated about database access, and integrates with many object relational layers (ORMs). There is out of the box support for Anorm, EBean, Slick, and JPA, but many customers use NoSQL or REST layers and there are many examples of Play using other ORMs not mentioned here.

§Slick

Slick is a Functional Relational Mapping (FRM) library for Scala that makes it easy to work with relational databases. It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred. You can also use SQL directly. Execution of database actions is done asynchronously, making Slick a perfect fit for your reactive applications based on Play and Akka.

§JPA

This is a example template showing Play with Java Persistence API (JPA), using Hibernate Entity Manager. It is included in the Play project itself.

§Anorm

This is an example template showing Play with Anorm using Play’s Anorm Integration. It also uses Play-Bootstrap for easy template scaffolding.

§EBean

This is an example template that uses EBean using Play’s Ebean integration. It also uses Play-Bootstrap for easy template scaffolding.

§Comet / Server Sent Events (SSE)

This is an example template that shows streaming responses through Comet or Server Sent Events, using Akka Streams:

§WebSocket

This is an example template that shows bidirectional streaming through the WebSocket API, using Akka Streams:

§Cryptography

This is an example template showing how to encrypt and sign data securely with Kalium:

§Compile Time Dependency Injection

Compile time dependency injection can be done in Play in a number of different DI frameworks.

There are two examples shown here, but there are other compile time DI frameworks such as Scaldi, which has Play integration built in, and Dagger 2, which is written in Java.

§Manual Compile Time Dependency Injection

This is an example template showing how to use manual compile time dependency injection and manual routing with the SIRD router, useful for minimal REST APIs and people used to Spray style routing:

§Macwire Dependency Injection

This is an example template showing compile time dependency injection using Macwire.

§Third Party Tutorials and Templates

The Play community also has a number of tutorials and templates that cover aspects of Play than the documentation can, or has a different angle. Templates listed here are not maintained by the Play team, and so may be out of date.

This is an incomplete list of several helpful blog posts, and because some of the blog posts have been written a while ago, this section is organized by Play version.

§2.5.x

§Dependency Injection

§Akka Streams

§Database

§2.4.x

§Semisafe

Semisafe has an excellent series on Play in general:

§Minimal Play

§Dependency Injection

§REST APIs

Justin Rodenbostel of SPR Consulting also has two blog posts on building REST APIs in Play:

§Slick

§RethinkDB

§Forms

§EmberJS

§AngularJS, RequireJS and sbt-web

Marius Soutier has an excellent series on setting up a Javascript interface using AngularJS with Play and sbt-web. It was originally written for Play 2.1.x, but has been updated for Play 2.4.x

§React JS

§2.3.x

§REST APIs

§Anorm

Knoldus has a nice series of blog posts on Anorm:

§Forms

§2.2.x

§Advanced Routing

§Path Bindables

§Templates

§User Interface

§Play in Practice

Next: Working with Play


Found an error in this documentation? The source code for this page can be found here. After reading the documentation guidelines, please feel free to contribute a pull request.