Spray is very feature-rich framework that could be exploited in a couple of different ways. Our goal is to understand the Spray philosophy, foundations, and design principles along with versioning policy.
- View Offline
- [Narrator] Hi, and welcome to section three of the course, Building REST(ful) Web Services with Spray. In this section, we're going to actually start building a real REST(ful) web services using Spray framework, applying in practice, all the knowledge we have acquired in the previous sections. We will gain understanding of the Spray framework by discussing its modular structure, philosophy, and design principals. Right after that, we'll get a close look on two core modules which play a key role in REST(ful) web services and API's development on top of Spray framework, Spray Routing and Spray Can.
Armed with this knowledge, we can start coding the skeleton of our book catalog, REST(ful) web services, and what could be a better end of the section than consuming our freshly developed REST(ful) web services. We will gain insights on how to use browsers or command line tools as clients for the HTTP based, REST(ful) web APIs. Now we're moving on to the first video of this section, where we are going to feel the magic of Spray framework, learn its philosophy, foundations, and design principles.
At the very last, we are going to spend some time talking about Spray versioning policy. It is going to help us to pick the right set of dependencies, like Akka, for our projects. In this video, we're going to take a look at Spray framework in general, starting from its proper definition and brief history. Understanding the design principles is very important to master any framework or library, and it's applicable to Spray as well. We will spend some time discussing the decisions which influenced Spray's design, concluding how Scala and Akka provided the necessary foundation to implement them.
Close to the end of this video, we're going to discuss how Spray's modular structure reflects its philosophy and provides the necessary building blocks at every layer of HTTP-based communication. The very important topic of compatibility between Spray, Akka, and Scala is going to be addressed as well. So far, we've always referred to Spray as a framework taking into account quite blurry definition of what framework actually is. In fact, Spray positions itself more like a suite of libraries than a framework.
For many of us, there's not much difference. However, there really is, and for simplicity, we're going to continue to refer to Spray as a framework or just Spray. Akka and Spray are somewhat age mates. The first official release of the Spray became available in 2011. Spray design is heavily influenced by a set of core, simple principles, which makes this framework a compelling choice for building REST(ful) web services and APIs.
All APIs built on top of spray are fully asynchronous. Blocking code is avoided whenever at all possible. Spray fully embraces the Actor Model and heavily relies on Akka for that. Most, if not all Spray components are carefully crafted for excellent performance in high load environments All Spray dependencies are very carefully managed to reduce the footprint. Spray is structured as a set of integrated, but loosely coupled components.
Every application only depends on the parts it actually needs. Spray components are structured to be easily testable. We already discussed that in one way or another, but it's worth repeating that Spray Foundations or Scala Programming Language, along with its library, and Akka framework, which in turn, is also written solely in Scala. Without such solid foundation, Spray framework probably would have never been created. Understanding the purpose and functionality of each Spray module is very important as it allows us to pick up the ones we really need.
Spray-IO provides a low level network input output layer for directly connecting Akka actors to asynchronous Java NIO sockets. Spray-Http provides an immutable model for HTTP requests, responses, and common headers. Spray-Httpx provides higher level tools for working with HTTP messages. Spray-Can provides a low level, low overhead, high performance, HTTP server and client built on top of Spray-IO.
Spray-Routing provides a high level routing, domain specific language, or simply DSL. For elegantly defining REST(ful) web services, Spray-Servlet serves as an adapter layer providing the capabilities to integrate with Java Servlet API. Spray-Client provides higher level client-side HTTP support. Spray-Caching provides fast and lightweight in-memory caching. Spray-JSON provides a lightweight, clean and simple JSON implementation in Scala.
Spray-Util is a small utility module used by all other modules. Spray-Testkit provides a DSL for easily testing Spray routing services. In this video and along the previous two sections, we have talked a lot about Scala, Akka, and Spray. However, we have never brought up the realities of building any kind of applications using Scala programming language, an ecosystem of its libraries. To put it in context, as Scala Programming Language evolves, new features are added to the language along with old ones being deprecated or removed.
There are many versions of Scala available in the world, but the most recent ones are 2.10 and 2.11.6. Every application, framework, or library, including Spray and Scala, are developed and released against one or several versions of Scala. Along this course, we're going to use the latest version, 1.3.3 of Spray framework built on top of Scala 2.11.6 and Akka 2.3.9.
In this video, we have seen the Spray framework in general, mentioned its philosophy and design principles and outlined our choice of the Scala, Akka, and Spray versions we are going to use from now on. The knowledge we have gained in this video should be of great help as we move forward and start building REST(ful) web services with Spray. In the next video, we're going to learn about Spray Routing Module and understand its role in defining REST(ful) web services and API endpoints.
Embark on an exciting journey into the universe of web development using the Scala programming language and frameworks—natural choices for back-end developers building highly scalable, reliable, and reactive RESTful web services and APIs. This training is the starting point for mastering the nonblocking and asynchronous programming models that lie in the heart of the Spray framework. It starts with an introduction to the REST architecture. Then switch gears to the Akka toolkit and framework, building a sample book catalog application along the way.
Once you've learned about the REST architectural style and Actor model—the foundations that the Spray framework is built upon—you'll shape out your own RESTful web services by providing simple route definitions. Further on in the course, author Andriy Redko delves into authentication and authorization, secure transport, documentation, testing, and caching support. Finally, you will learn how to develop the Spray client API to call external web services.
- The Actor model and Akka framework
- RESTful architecture principles and constraints
- Building RESTful services
- Core Spray framework modules such as spray-can, spray-routing, spray-json, spray-caching, and spray-client
- Securing RESTful web services and APIs with Spray
- Configuring Spray applications with HTTPS support
- Documenting Spray RESTful web services using Swagger
- Caching basics
- Calling external RESTful services