Choosing a Scala web framework

Andrea picture Andrea · Aug 1, 2012 · Viewed 19k times · Source

I am about to start a project for a web application that should run on a Tomcat server. I have decided to go for Scala - the other alternative where I work being Groovy - essentially for type safety. I am now faced with the task of choosing the right tools for the job.

The project I will need to develop will be accessed only through a JSON API. It will interact both with its own database and with two external services, which expose respectively a JSON and XML API. I will also need to be able to schedule periodic jobs where my application will execute various synchronization tasks with these external services.

For the database, I would like to be able to define my models in Scala and automatically generate the schema. If the need arises to change my models, I would like to have migrations to handle it.

For this application, I am trying to evaluate Lift, Play! 2 and Scalatra.

  • Lift was my first choice. It is the most mature of the three projects, and seems to be considered highly secure (I do not want to compromise on security). Moreover it features what seems to be the best JSON handling library in Scala. Still, after dabbling a bit with it, I am not sure this would be the right choice. The documentation is not exactly the best I have seen. Moreover, Record + Squeryl seems to me a better abstraction than Mapper, but documentation for this use is even more scarce. Finally, although Lift can certainly be used to create a web service, it seems that its real strength lies in the state handling, and so I am not convinced that the additional complexity is needed for my project.

  • Play! 2 seems to have a better documentation, and looks more familiar to me (I come from a Django background). Again, its default database abstraction does not really appease me: ANORM relies on SQL, which does not help with type checking. I would have to use Squeryl anyway, and I am not sure whether the documentation for this use case is as good. Moreover, deploying Play! 2 applications is at the moment moer complicated than I'd like. One has to install Play! on the production server, and I am not sure this is an option where I work. Otherwise, there is a plugin to to make it work with servlets containers, but it is very new and I am not sure how stable/reliable it is.

  • Finally there is the option of using Scalatra. Scalatra seems very easy to set up, and it is designed exactly to create web services. The compromise is that Scalatra does not offer much functionality. It does not integrate with existing ORMs or suggest how to organize the model part of the application, and it does not help in designing cron or command line tasks. I am also not sure about the long term future of the project.

What do you think would be the best choice for my task?

Answer

sourcedelica picture sourcedelica · Aug 1, 2012

If you are coming from a MVC background then Play will feel the most familiar. Lift is not MVC and it takes some time to wrap your head around it.

There is no reason that you can't use Scala with a Java-based framework like Jersey, Spring MVC, Dropwizard, Restlet, RESTEasy, etc. Or you could use Scala with Grails just like you can use Java with Grails. Note - Groovy has type safety starting with version 2.0 so that's something to consider.

If you are thinking about Scalatra then don't forget Spray, Unfiltered, BlueEyes...

Be sure to check out Matt Raible's comprehensive comparison of web frameworks. And these other SO questions: Scala framework for a Rest API Server?, How to implement a REST Web Service using Akka?