Published
Table of Contents #
Intro #
The Play Framework is a modern web application framework for Java and Scala. The framework is developer-friendly and lightweight but allows developers to build scalable services without sacrificing developer productivity. A typical use case for this framework is building a client for a RESTful Web Service.
One of the things that makes Play attractive is the advantage it has over servlet-based web frameworks. You’ll also be sure to appreciate its dependency injection feature. This will be useful when wanting to pull in functionality from outside components into your controllers.
The framework is open source. You can find the source code on Github at:
https://github.com/playframework/playframework
Getting Started with Play #
Once you have SBT installed on your machine, it’s fairly easy to get started. You can scaffold a new Play Scala project with the following sbt command:
C:\demos>sbt new playframework/play-scala-seed.g8
...
This template generates a Play Scala project
name [play-scala-seed]: play-scala-demo
organization [com.example]: com.uequations
Template applied in C:\demos\.\play-scala-demo
Once you get through the prompts, you’ll be able to cd into your newly created project and run it:
This may take some time. Once it’s up and running, you can point your browser to http://localhost:9000 to render the welcome page.
sbt run
...
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Enter to stop and go back to the console...)
...
2021-05-18 17:05:08 INFO play.api.Play Application started (Dev) (no global state)
The welcome page should simply say, “Welcome to Play!” If you’re on a Windows machine, ctrl + C should stop the app. If you’re curious, sbt test will run the tests.
D:\demos\play-scala-demo>sbt test
...
[info] HomeControllerSpec:
[info] HomeController GET
...
[info] Tests: succeeded 3, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 40 s, completed May 18, 2021, 5:13:13 PM
If you’re even more curious, you can browse the dependencies to see if you can find a dependency on Akka Streams. Play is built on Reactive principles from the ground up.
Play is RESTful by default. Next time, we’ll use it to build a simple RESTful API.
Play Framework on the Social Media Platforms #
References #
- Introduction to Play in Java. https://www.baeldung.com/java-intro-to-the-play-framework. Accessed 17 May 2021.
- Webber, Kevin. Work Stealing: What Makes the Play Framework Fast. https://blog.redelastic.com/work-stealing-what-makes-the-play-framework-fast-4b71fa7758d5. Assessed 17 May 2021.
- The Play Framework at LinkedIn. https://engineering.linkedin.com/play/play-framework-linkedin. Accessed 17 May 2021.
4 .Introduction to the Play Framework in Scala. https://www.baeldung.com/scala/play-framework-intro. Access 18 May 2021. - Play Framework - Part of Akka Platform. https://www.lightbend.com/play-framework-part-of-akka-platform. Accessed 18 May 2021.
Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖!
For feedback, please ping me on Twitter.