8 Frameworks to Build A Web API In Scala Kristopher Sandoval June 26, 2018 Scala is a powerful language that has quickly become a favorite among many developers. A language, however, is just a starting point — not every function is going to be covered by the language core. Accordingly, some awesome frameworks have been created to make Scala just that much better. Today, we’re going to look at 8 powerful frameworks for Scala. We’ll discuss a little bit about each, and list out some pros and cons. Keep in mind that the best choice of framework is always going to be that which matches your specific project’s requirements – accordingly, consider these cues, but decide based upon your own project requirements what works best for you. 1. Play Framework The high velocity web framework for Java and Scala Play Framework is an open-source Scala framework that was first released in 2007. It’s currently developed by Lightbend, Zengularity, and its community of user developers. The core functionality of the framework is based upon leveraging JVM and its related libraries to form RESTful applications. It is currently used by some rather large name websites, including LinkedIn, Samsung’s IoT Artik platform, and education site Coursera. At time of writing, Play 2.6 is the current version of Play, having superseded Play 1 in development. Benefits Intimately related to JVM, and as such, Java developers will find it familiar and easy to use. Extensive support for a variety of toolsets and IDE systems. It is based entirely upon functional programming concepts, and promotes API-first RESTful design practices. Play 2 is reactive, allowing for remote calls in parallel. This means that it works well with WebSockets and other related server-centric approaches. It offers a wide range of framework supporting structures for asset compilation, format handling, database integrations, etc Play is open source, which benefits adoptees with greater security and a consistently reviewed codebase. Drawbacks There are many great plugins in the community, sure, but their stability and usefulness aren’t always guaranteed. Play 2 utilizes the SBT build system. While it’s very powerful, some have offered concerns about its use of implicits, wildcard imports, and other eccentricities that make infrastructure development and integration extremely difficult. Related: Building a REST API in Java and Scala Using Play Framework 2. Finch Scala combinator library for building Finagle HTTP services Finch is a modular system of HTTP primitives that function in concert to form HTTP APIs. The entire framework is centered upon the concept of composability, and as such, it is a highly modular, customizable system. “Finch is a thin layer of purely functional basic blocks atop of Finagle for building composable HTTP APIs. Its mission is to provide the developers simple and robust HTTP primitives being as close as possible to the bare metal Finagle API.” Benefits Finch utilizes functional blocks to form its framework, and as such, it is extremely modular. That being said, it offers some rather robust HTTP primitives, which makes it great for rapid development and testing. For this reason, Finch is a great fit for smaller projects and startups. Due to the nature of how it is structured, it is very fast and highly functional for a variety of systems. Drawbacks The main drawback is simply the fact that its structured more to be a bare minimum implementation that allows for further implementation and development iteration. Is not considered as a full-stack solution. 3. Akka HTTP Akka HTTP modules implement a full server and client-side HTTP stack on top of akka-actor and akka-stream. Akka HTTP is a highly modular and extremely powerful Akka implementation for Scala. It was created with the concept in mind of development occurring within a “frame,” where pre-formed choices and functionalities guide development. Akka HTTP was created as “not-a-framework,” providing many of the tools for development without forcing any choices on the developer. As the documentation describes, “It’s not a web-framework but rather a more general toolkit for providing and consuming HTTP-based services. While interaction with a browser is of course also in scope it is not the primary focus of Akka HTTP.” Benefits The greatest benefit of Akka HTTP is the fact that it’s integrated with Akka functionality. Like Akka, it supports a great many systems that can perform parallel commands and advanced computation processing. Akka HTTP has a great support base of developers and contributors, all aligned under Lightbend. Additionally, it has excellent documentation and an easy to understand support center. Drawbacks Akka HTTP is slower than other implementations on this list, and as such, while it scales efficiently, it’s already starting behind the pack, so to speak. Lightbend is a great organization, but getting stuck into a single vendor can be worrying for many organizations. Vendor lock-in can be expensive and hard to break, so this should be considered before adopting the solution. 4. Chaos A lightweight framework for writing REST services in Scala Chaos is a framework from Mesosphere. It was designed specifically for RESTful development as an answer to the developer’s previous experiences with Dropwizard and Twitter Commons in the Java Framework space. They designed Chaos to be a more streamlined response to frameworks like Play, stating that they avoided Play because “it does many things besides REST, which adds unnecessary baggage.” Chaos (Greek χάος, khaos) refers to the formless or void state preceding the creation of the universe or cosmos in the Greek creation myths. Similarly, Chaos (the framework) precedes creation of a universe of services. Benefits Chaos was designed to be easy to use and familiar with users who utilize Scala. All of the libraries it utilizes are well-tested and well-supported, offering a great amount of documentation and knowledge bases from which to test, iterate, and development upon. Drawbacks Unfortunately, Chaos is essentially another lightweight framework that glues libraries together and calls it a day (Jersey, Guava, Jetty, Jackson, and Coda Hale’s Metrics). While it does some interesting things, it’s fundamentally limited by that approach. As the creators say, it does one thing really well – REST. If you’re not building a RESTful service, or if you’re building a service that by design has to integrate some eccentricities, the default libraries in Chaos might not be the best integrations you could ask for. 5. Lift A powerful, secure web framework Lift is a highly secure and scalable framework. From the ground up, Lift was designed specifically to address a multitude of security concerns, including cross site scripting and code injection. For this reason, Lift has come to be known as a highly secure option for highly secure Scala APIs. Lift describes itself as secure, developer-centric, designer-friendly, scalable, modular, and interactive. Benefits Lift is designed around security from its most basic level. Form value obfuscation and the use of prepared statements, in addition to other techniques, Lift promotes code-wide security in standard implementations. Lift is quite fast, to the point that this is often its main selling point. Database queries are concise, calls are handled very quickly, and its support for REST approaches to content handling is helpful. Drawbacks The Lift community is somewhat small compared to the larger options in this list, but it has existed for a very long time, so there’s ample documentation. That documentation, however, is often out of date, and if it’s not out of date, isn’t always the best. That’s not to say there’s no good documentation – there’s just as much good as there is bad, which is part of the problem. Lift by its nature started off quite stateful, and this is still present in the current codebase, Accordingly, scaling lift is somewhat tricky, and when moving to REST, can cause some issues in what data is transferred, what is serialized and shared, and how requests are routed. 6. BlueEyes A lightweight Web 3.0 framework for Scala, featuring asynchronous architecture, high-performance, scalability, high usability, and a functional, composable design. BlueEyes bills itself as a “Web 3.0 framework for Scala,” focusing entirely on performance and composability. It benefits greatly from being lightweight by nature, and has positioned itself for quick development and agile web services. Benefits BlueEyes is highly scalable, and is designed specifically for high performance applications that require modularity. BlueEyes benefits from being purely asynchronous — in such situations, it’s a strong, almost purpose built solution. By being built around the concept of modularity and composability, Blueeyes is a great choice for any application that might have specific requirements and standards to meet. Drawbacks By design, BlueEyes does not have any support for server-side generation of HTML, CSS, or JavaScript. It also does not serve static files. Its entire purpose is simply to build RESTful services consumed by clients. While this sounds great, if you have any need for that kind of functionality, you’ll need to use an external plugin or solution. BlueEyes is entirely asynchronous — if your application requires synchronous functionality, BlueEyes is not a good choice. 7. Slick A modern database query and access library for Scala. Slick is a modern framework developed around the ideas of database querying and access. It was designed to function similarly to the basic Scala collections system, but with greater amounts of control over both access in general and the manner in which it is transferred. As the Slick Documentation describes, “It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred. You can write your database queries in Scala instead of SQL, thus profiting from the static checking, compile-time safety and compositionality of Scala. Slick features an extensible query compiler which can generate code for different backends.” Benefits Slick is designed to easily connect to databases and sources, and as such, has a highly extensible series of support structures. This makes it great for applications that are tying into many data points from disparate sources. Likewise, Slick also offers a high extensible query compiler, which joins Slick based applications into a wide range of backend systems. Drawbacks Slick has many benefits that set it apart from other options, but it is focused around an asynchronous design ethos, which is not needed in some applications. While it supports a wide range of databases, poor performance has been noted in MySQL implementations due to eccentricities in the MySQL database system. The heavy focus on DBIO that allows for extensive database integration is also a major negative in that it makes for a substantial learning curve. As such, it may not be the best solution for novice or lean developers. 8. Scalatra A simple, accessible and free web micro-framework. Scalatra is an open source framework that is functionally a port of Ruby’s Sinatra. It is a microframework that intends on being the beginning stage of an implementation, rather than a full-stack solution. It was first released in 2009, with large organizations such as LinkedIn adopting it to power their early API systems. According to the Scalatra documentation, “it combines the power of the JVM with the beauty and brevity of Scala, helping you quickly build high-performance web sites and APIs.” Benefits Scalatra is very efficiency for RESTful applications, and as such is a great choice for anyone trying to design an asynchronous lightweight stateless application. The userbase for Scalatra has pushed it to be quite popular. It is considered by many to be an almost default framework of choice. Its entire purpose is framed around Sinatra and JVM, and as such, is primed for rapid high-performance web service construction. Drawbacks Scalatra is not very useful for synchronous applications, and like others on this list, if that’s your ethos of choice, Scalatra is a poor option. Scalatra is designed to be a basic service, not a fully complete one, and as such, it functions great as a core, but suffers somewhat as a full-stack implementation. We’ve also compiled web framework lists in other languages: Go Node.js PHP Clojure Conclusion There are so many Scala frameworks in the ecosystem that it’s hard to choose just 8 to discuss. Regardless of what your project requirements are, there’s a good chance that a framework exists for your given situation. If it doesn’t, there’s just as good a chance that a framework exists that allows you to form modular support for those requirements – that’s the power behind extensibility in frameworks, allowing for greater manipulation and extension. What do you think? What’s your favorite Scala framework? If we missed one on this list, let us know below – we might feature it in the future! The latest API insights straight to your inbox