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.
§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
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 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.
- play-isolated-slick: This template uses a multi-module that hides Slick 3.x behind an API layer, and does not use Play-Slick integration. It also contains sbt-flyways and use Slick’s code generator to create the Slick binding from SQL tables.
- play-scala-intro: This template uses PlaySlick as part of a single Play project.
- Computer Database with Play-Slick: This template uses PlaySlick. You will need to clone the
play-slickproject from Github and type
project computer-database-samplein SBT to get to the sample project.
This is a example template showing Play with Java Persistence API (JPA), using Hibernate Entity Manager. It is included in the Play project itself.
This is an example template showing Play with Anorm using Play’s Anorm Integration. It also uses Play-Bootstrap for easy template scaffolding.
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:
This is an example template that shows bidirectional streaming through the WebSocket API, using Akka Streams:
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.
- Dependency Injection in Play Framework using Scala by Krzysztof Pado.
- Akka Streams integration in Play Framework 2.5 by Loïc Descotte.
- Playing with Akka Streams and Twitter by Loïc Descotte.
- Play Database Application using Slick, Bootstrap: This is an activator project for showcasing best practices and providing a seed for starting with Play & Slick, By Knoldus.
Semisafe has an excellent series on Play in general:
- Templates, Routes and AJAX
- Upgrading the Framework
- Database Access
- Async Futures and Actors
- Optimistic Future Composition
- React UI Coffeescript
- CSRF Protection
- A Play Application in 38 Lines by Lloyd Chan, showing a “Sinatra” style of Play application.
- Playframework 2.4 Dependency Injection (DI) by Marius Soutier.
- Testing with Dependency Injection by Michael Pollmeier.
- Compile Time Dependency Injection with Play 2.4 by Loïc Descotte.
Justin Rodenbostel of SPR Consulting also has two blog posts on building REST APIs in Play:
- Building a Simple REST API with Scala & Play (PART 1)
- Building a simple REST API with Scala & Play! (PART 2)
- Play framework, Slick and MySQL Tutorial by Pedro Rijo.
- How to add a form to a Play application by Chris Birchall of the Guardian.
- HTML 5 Device Orientation with play, ember and websockets by Cake Solutions (with activator template)
§AngularJS, RequireJS and sbt-web
- RequireJS Optimization with Play 2.1 and WebJars
- Intro to sbt-web
- Understanding sbt and sbt-web settings
- Play Angular Require Seed Updates
- ReactJS Tutorial with Play, Scala and WebJars by Fabio Tiriticco.
- A basic example to render UI using ReactJS with Play 2.4.x, Scala and Anorm by Knoldus / activator template
- Playing with Play Framework 2.3.x: REST, pipelines, and Scala by Sampson Oliver.
Knoldus has a nice series of blog posts on Anorm:
- Employee-Self-Service – Building Reactive Play application with Anorm SQL data access – (Part-1)
- Employee-Self-Service – Building Reactive Play application with Anorm SQL data access – (Part-2)
- Employee-Self-Service: Reactive and Non-Blocking Database Access using Play Framework and Anorm – (Part-3)
- Employee-Self-Service: Reactive and Non-Blocking Database Access using Play Framework and Anorm – (Part-4)
- Example form including multiple checkboxes and selection by Philip Johnson.
- UX-friendly conditional form mapping in Play by the VOA
- Advanced routing in Play Framework by James Roper.
- Play Routes – Part 1, Basics by Marius Soutier.
- Play Routes – Part 2, Advanced Use Cases by Marius Soutier.
- How to implement a custom PathBindable with Play 2 by Julien Richard-Foy.
- Play Framework 2.0 Templates – Part 1, Parameters by Marius Soutier.
- Composite user interface without boilerplate using Play 2 by Julien Foy.
§Play in Practice
- Play in Practice by Will Sargent.
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.