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.
§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.
All of the following projects can be downloaded as example projects from the download page.
There are two Play Seeds that are designed expressly for getting started with new Play applications. They contain a hello world controller and view template, filters, and nothing else.
If you have sbt 0.13.13 or higher installed, you can create your own Play project using
using a minimal
giter8 template (roughly like a maven archetype). This is a good choice if you already know Play and want to create a new project immediately.
g8Scaffold form from sbt to create the scaffold controller, template and tests needed to process a form.
sbt new playframework/play-java-seed.g8
sbt new playframework/play-scala-seed.g8
§Play Starter Projects
For people using Play for the first time, there is a starter project which introduces Play with some sample controllers and components.
or you can download it as an example project from the download page.
§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.