Introduction to play framework

Reading Time: 3 minutes

In this blog we will discuss about the basics of the play framework. So let’s start with the introduction of the play framework.

What is Play framework?

Play is a lightweight open source framework develop by the Lightbend. Companies such as LinkedIn, Coursera, Verizon and many more already work with Play. So basically it is a web framework for the JVM that breaks away from the Servlet Specification. Therefore it embraces a fully reactive programming model through the use of futures for asynchronous programming, work stealing for maximising available threads, and Akka for distribution of work.

Why play framework?

Play aims to make it easy for developers to work and optimize their productivity by using convention over configuration, hot code reloading, and by displaying application errors over the browser.

  • Asynchronous. Built on Netty, this makes I/O work without any blocker, with independent threads. Its compatibility with Akka, also makes it possible to create a fully asynchronous application.
  • Open source. The whole project is visible to developers and changes may be accepted if errors or bugs are solved. This also applies for framework improvements.
  • Error representation. Play shows exactly the place where the error happened, including the file, line, and column.
  • Constant updates. The Play framework is always updating and you can keep track of this on their website. Play is compatible with many of the recent useful technology stacks such as JSON, ORM, SQL and NoSQL.
  • Languages support. The Play framework is built on Scala but also supports Java, so there’s the chance to program on either one of these languages, or both.

Play framework project directory structure-:

Play Application Folder Structure

  • app: Folder that contains the source code of the application.Also contains controllers and views.And For any enterprise application, if you want to add other source code folder like model, you can very well create “model” folder under “app” and keep all your domain models under it.
  • conf: Folder that contains the configuration of the application.
  1. application.conf –> It contains all the application related configurations like database connectivity details, web application context path details.
  2. logback.xml –> It contains the application logging related information .
  3. routes –> you need to configure all the REST services end points over here like post, get and other routes.
  • project:This folder contains plugins.sbt and build.properties file which contains plugins related information.
  • public: It contains all the static assets like Javascript, images, and CSS.
  • test: This contains all the unit tests.
  • build.sbt This file contains all the dependencies needed to run the application.

Create and Run the play application

Run the following commands to create the play application

sbt new playframework/play-scala-seed.g8
name [play-scala-seed]: scala-rest-api-example
organization [com.example]: com.example

Open the project folder name scala-rest-api-example in your intelliz.

And execute the following command to run the application

sbt run

Then hit the localhost:9000 in your browser or in your postman application to compile and see the application the application content.

b2ap3_thumbnail_scala-play-start-output.png

Also you can add your routes in controllers to see your content according to your application requirement.

I hope this blog will help you to understand the basics of the play framework.

In my next blog i will explain more about play framework.

References-:

https://www.playframework.com/documentation/2.8.x/Home

knoldus