So I've decided on Spray.io for my new RESTful project. It took some time to decide which Scala framework to use but after a thorough look at the various frameworks I've decided that Spray.io would be the most ideal one for the project I'm taking on. I think either one would have been a good choice but at the end my decision was based on simplicity, readability and relevance. I don't think one can go wrong with either but it does come down to a personal taste really. It was a hard decision considering how much support Play has and that is not to mention the backing of Typesafe, but the community and adoption is also important which Spray.io is in no way lacking.
To understand why I decided on Spray.io I should first explain roughly the requirements for the project. I'm going to build a RESTful based application which I can use the REST api to build web apps, mobile apps aswell as providing the API for third parties to use. Therefore it's an API first application, this being a crucial part I needed something light weight which will allow me to grow when required. Scalability is important as I want to keep it very light to begin with and scale up again when required. Securing the API by the use of Authentication and Authorization is also a priority and coming from a Spring background it is hard to beat what Spring Security can do for your application. I have used Spring Security since the early days before it was part of the Spring Framework (aka Acegi Security).
I chose Scala as I've always wanted to get into it, I wanted the flexibility that the language provides but with the type safety that Java has. I also wanted to have access to the Java API as well as direct access to Java based libraries, this is very important to me because of the nature of the project. But this post isn't about why I chose Scala but rather why I chose Spray.io.
I have looked at all the frameworks in the Scala eco system, some more thoroughly than others, but my decision drilled down to two, Play framework or Spray.io (not a framework :-) Play was quite easy to get into, the command line interface was very similar to Grails and Ruby on Rails, so it's a very pleasant environment to build a web app in Scala. But that was the difference there, I am not building a web app but rather a RESTful API. I did my research and found that I could build my RESTful app using Play and use only what I needed, however, I quickly found that the framework was very heavily targeted towards a web application. I did look at Play mini but I only looked at it after I played around with Spray.io and by then my preference rested more towards Spary.io.
Play, however, met all my demands in one way or another but maybe it was too heavy or maybe my ego required a bit more of a challenge that made me look further into Spray.io. Play is based on Netty whereas Spray.io uses spray-can (can also use Jetty) which offers the same asynchronous performance (using Akka.) Play uses Akka and allows a developer to make use of Akka actors as does Spray.io, however, Spray.io seems to provide a better integration there than Play does, but with very minimal differences. Play offers a DIY method of security as does Spray.io, however, there is a third party module (Secure Social) that provides everything one needs in terms of security for the Play framework. Having said that, Spray.io has a nice integrated approach to authentication and authorization by using the relevant directives.
As mentioned already, Play has the backing of Typesafe which is a huge plus when it comes to the survival of a framework or a given tool suite. However, from my investigations Spray.io has been adopted by various global companies and with the outstanding active and helpful community I know Spray.io will be around longer than web 2.0, 3.0 or even n.0.
What it comes down to is that Play is a framework (if you had not noticed so far in my post) and Spray.io is a suite of libraries that do what is required of them for the purpose their meant for, and try their best to stay out of your core application.
I plan to deploy the application to Cloud Foundry and Play was the best choice there, but I found that I can deploy my Spray.io application as a standalone application so that isn't going to be an issue. But the first class support for Play both on Cloud Foundry and Heroku is a huge plus for anyone using Play.
If I get time I will put up some code examples of the Spray.io REST implementation but for now here are some useful links for anyone interested:
Here are two links for cloud foundry:
Scala/Spray.io with MongoDB:
Casbah - https://github.com/mongodb/casbah
JanxSpirit g8 template - https://github.com/JanxSpirit/spray-mongodb.g8
Salat - https://github.com/novus/salat