§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.
§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.
§Play Seeds
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 sbt new
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.
Note: If running Windows, you may need to run sbt using
sbt.bat
instead ofsbt
. This documentation assumes the command issbt
.
Type g8Scaffold form
from sbt to create the scaffold controller, template and tests needed to process a form.
§Java
sbt new playframework/play-java-seed.g8
§Scala
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 non-opinionated 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.
- 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 Play Slick as part of a single Play project.
- Computer Database with Play-Slick: This template uses Play Slick. You will need to clone the
play-slick
project from Github and typeproject computer-database-sample
in SBT to get to the sample project.
§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
§Play Framework Tutorial Video Series
A tutorial video series by Radix Code provides an initial overview to Play, walking through initial IDE setup, defining routes, creating a CRUD application, enabling ORM support, and customizing the views with bootstrap.
- Debug Play Application in IntelliJ IDE
- Debug Play Application in Eclipse IDE
- How Routing Works
- Add Support for MySQL in Play
- Include Bootstrap and jQuery
- Form Validations
- Creating Custom Error Pages
§Dependency Injection
- Dependency Injection in Play Framework using Scala by Krzysztof Pado.
§Akka Streams
- Akka Streams integration in Play Framework 2.5 by Loïc Descotte.
- Playing with Akka Streams and Twitter by Loïc Descotte.
§Database
- Play Database Application using Slick, Bootstrap: This is an example project for showcasing best practices and providing a seed for starting with Play & Slick, By Knoldus.
§Forms and Validators
- Controller Forms: This provides examples of using forms and custom validators within a controller.
- Json Validators: This guide lists methods of validating json against a customized case class or trait.
§REST APIs
- Making a REST API in Play, a multi-part guide using the Scala API, by the Lightbend Play Team.
- Play API REST Template by Adrianhurt: shows how to implement a complete Json RESTful API with some characteristics such as Authentication Token, pagination, filtering, sorting and searching and optional enveloping.
§Sub-projects
- Play Multidomain Seed by Adrianhurt: tries to be a skeleton for a simple multidomain project (www.myweb.com and admin.myweb.com). It shows you how to use subprojects for that and how to share common code. It is also ready to use with Webjars, CoffeeScript, LESS, RequireJS, assets Gzip and assets fingerprinting. Please, check the readme file for more details.
- Play Multidomain Auth by Adrianhurt: this is a second part of play-multidomain-seed project. This project tries to be an example of how to implement an Authentication and Authorization layer using the Silhouette authentication library. It also uses Play-Bootstrap for easy template scaffolding.
§Upgrading
- Upgrading from Play 2.3 to Play 2.5 by Gregg Hernandez: Learn how to deal with common problems when upgrading to Play 2.5, including maintaining legacy behavior, transitioning to Akka Streams, and implementing compile-time dependency injection.
§2.4.x
§Semisafe
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
§Minimal Play
- A Play Application in 38 Lines by Lloyd Chan, showing a “Sinatra” style of Play application.
§Dependency Injection
- 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.
§REST APIs
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)
§Slick
- Play framework, Slick and MySQL Tutorial by Pedro Rijo.
§RethinkDB
§Forms
- How to add a form to a Play application by Chris Birchall of the Guardian.
§EmberJS
- HTML 5 Device Orientation with play, ember and websockets by Cake Solutions (with activator template).
§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.
- RequireJS Optimization with Play 2.1 and WebJars
- Intro to sbt-web
- Understanding sbt and sbt-web settings
- Play Angular Require Seed Updates
§React JS
- 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.
§2.3.x
§REST APIs
- Playing with Play Framework 2.3.x: REST, pipelines, and Scala by Sampson Oliver.
§Anorm
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)
§Forms
- Example form including multiple checkboxes and selection by Philip Johnson.
- UX-friendly conditional form mapping in Play by Nick Tune.
§2.2.x
§Advanced Routing
- 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.
§Path Bindables
- How to implement a custom PathBindable with Play 2 by Julien Richard-Foy.
§Templates
- Play Framework 2.0 Templates – Part 1, Parameters by Marius Soutier.
§User Interface
- Composite user interface without boilerplate using Play 2 by Julien Foy.
§Play in Practice
- Play in Practice by Will Sargent.
Next: Working with Play