Saturday, July 21, 2012

Play! framework. First experience.

Do we always need to use complex and powerful frameworks such as Spring, Wicket, Struts with different multiple-level functionalities. Of course not. Sometimes we need a lightweight framework for developing simple java-based web applications. Lately I tried a new Play framework 2.0.1 to develop a simple Rest applications.

The framework is based on MVC pattern, the connection between different elements is understandable. To understand how the framework performs you do not need a lot of time. We have models (could be represented as hibernate entities in a table format)

Views (consist of scala/html/coffescript)

Controllers (perform some operations and redirect users to the views)

Framework proposes to use in-memory H2 database for initial development. On the other hand, to use another database we have to change config file. In order to map client request to a specific controller is used config file with name route. Here are not used annotations(like in Spring), everything is done in a separate file(after Spring I thing that annotations are the best!!!). The example of route file is:

# Routes
 # This file defines all application routes (Higher priority routes first)
 # ~~~~
# Home page GET / controllers.Application.index()
# Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
 # Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)

What I liked is its speed. In Spring we use JRebel, Play framework does not need that plugin, we could edit/change our product live. Just change the code and press F5 and YES everything is changed. WE could change everything, config files, html etc. Of course it is a big plus. The Error messages are represented in a fancy way. It is really nice!


And yes it supports Scala. You can develop with Scala or with Java or  Scala and Java simultaneously. 

IMHO, it’s a good possibility to develop not complex applications. Its just very quick and fancy framework for limited needs. Try it out, understand the concepts and start developing. It is simple. Its very simple.

No comments:

Post a Comment