Introducing spray - RESTful web services on top of Akka
For some time now there has been increasing buzz around Akka as “the platform for the next generation event-driven, scalable and fault-tolerant architectures on the JVM” (http://akka.io). With the Akka team recently having released version 1.0 of its product more and more JVM developers (with Scala devs certainly being the majority) are turning to Akka as the enabler for building highly concurrent applications on the JVM with relative ease.
The backbone of Akkas services is its implementation of the actor model, which is often hailed as being the most mature of the several competing actor implementations in Scala. On top of the actor core Akka provides a number of add-on modules, one of them being the HTTP module. Akka HTTP comes with a component called “Mist”, which is described as follows (quote from the Akka website):
The Mist layer was developed to provide a direct connection between the servlet container and Akka actors with the goal of handling the incoming HTTP request as quickly as possible in an asynchronous manner. The motivation came from the simple desire to treat REST calls as completable futures, that is, effectively passing the request along an actor message chain to be resumed at the earliest possible time. The primary constraint was to not block any existing threads and secondarily, not create additional ones. Mist is very simple and works both with Jetty Continuations as well as with Servlet API 3.0.
Akka Mist provides an excellent basis for building RESTful web services in Scala since it combines good scalability (enabled by its asynchronous, non-blocking nature) with general lightweight-ness. However, in its current 1.0 state Mist is nothing more than a glue layer. It delivers a great foundation but falls short of providing the developer with things like a routing infrastructure or testing support.
This is what spray was built for.
spray is a light-weight framework for building RESTful web services on top of Akka actors and Akka Mist. It gives you the following things:
- Completely asynchronous, non-blocking, actor-based request processing for efficiently handling very high numbers of concurrent connections
- Powerful, flexible and extensible internal Scala DSL for declaratively defining your web service behavior
- Immutable model of the HTTP protocol, decoupled from the underlying servlet container
- Full testability of your REST services, without the need to fire up containers or actors
In its current state spray does not attempt to provide for frontend development needs (like view templating and AJAX support). If you are looking for a traditional MVC web framework for Scala you should check out the Lift Web Framework.
The spray team is eagerly awaiting your feedback…
Let us know, how we can make developing RESTful web services in Scala even more productive (and fun)!