Asynchronous API Design
So far, we have developed RESTful web services based on the imperative model, where calls are synchronous. What if you want to make code async and non-blocking? This is what we are going to do in this chapter. You’ll learn about asynchronous API design in this chapter, where calls are asynchronous and non-blocking. We’ll develop these APIs using Spring WebFlux, which is based on Project Reactor (https://projectreactor.io). Reactor is a library for building non-blocking apps on a Java virtual machine (JVM).
First, we’ll walk through the reactive programming fundamentals, and then we’ll migrate the existing e-commerce REST API (which we learned about in Chapter 4, Writing Business Logic for APIs) to an asynchronous (reactive) API to make things easier by comparing the existing (imperative) way and reactive way of programming. The code will make use of R2DBC for database persistence, which supports reactive programming.
We’...