I've been diving more and more into scala the last couple of months. Scala together with the "Play Framework" provides you with a very effective and quick development environment (as soon as you've grasped the idiosyncrasies of the Scala language, that is).
The guys behind the Play framework have been hard at work at the new version Play 2.0. In Play 2.0 scala plays a much more important role, and especially the complete build process has been immensely improved. The only problem so far, I've encountered with Play 2.0 is the lack of good documentation. The guys are hard at work at updating the wiki, but its often still a lot of trial and error to get what you want. Note though, that often this isn't just caused by Play, I also sometimes still struggle with the more exotic Scala constructs ;-)
In this article, I'll give you an introduction into how you can accomplish some common tasks in Play 2.0 using Scala. More specifically I'll show you how to create an application that:
- uses sbt based dependency management to configure external dependencies
- is edited in Eclipse (with the Scala-ide plugin) using the play eclipsify command
- provides a Rest API using Play's routes
- uses Akka 2.0 (provided by the Play framework) to asynchronously call the database and generate Json (just because we can)
- convert Scala objects to Json using the Play provided Json functionality (based on jerkson)
I won't show the database access using Querulous, if you want to know more about that look at this article. I'd like to convert the Querulous code to using Anorm. But since my last experiences with Anorm were, how do I put this, not convincingly positive, I'm saving that for a later day.
Creating an application with Play 2.0
Getting up and running with Play 2.0 is very easy and is well documented, so I won't spent too much time on this. For complete instruction see the Play 2.0 Wiki. To get up and running, after you you have downloaded and extracted Play 2.0, take the following steps:
Read the rest of the article at the following URL: