Chapter 11. Developing reactive APIs


This chapter covers

  • Using Spring WebFlux
  • Writing and testing reactive controllers and clients
  • Consuming REST APIs
  • Securing reactive web applications

Now that you’ve a good introduction to reactive programming and Project Reactor, you’re ready to start applying those techniques in your Spring applications. In this chapter, we’re going to revisit some of the controllers you wrote in chapter 6 to take advantage of Spring 5’s reactive programming model.

More specifically, we’re going to take a look at Spring 5’s new reactive web framework—Spring WebFlux. As you’ll quickly discover, Spring WebFlux is remarkably similar to Spring MVC, making it easy to apply, along with what you already know about building REST APIs in Spring.

11.1. Working with Spring WebFlux

Typical Servlet-based web frameworks, such as Spring MVC, are blocking and multithreaded in nature, using a single thread per connection. As requests are handled, a worker thread is pulled from a thread pool to process the request. Meanwhile, the request thread is blocked until it’s notified by the worker thread that it’s finished.

11.2. Defining functional request handlers

11.3. Testing reactive controllers

11.4. Consuming REST APIs reactively

11.5. Securing reactive web APIs