Serving data with a reactive GET method
Web controllers typically do one of two things: serve up data or serve up HTML. To grok the reactive way, let’s pick the first since it’s much simpler.
In the previous section, we saw a simple usage of Reactor’s Flux type. Flux is Reactor’s implementation of Publisher and provides a fistful of reactive operators.
We can use it in a web controller like this:
@RestController public class ApiController { @GetMapping("/api/employees") Flux<Employee> employees() { return Flux.just( // new Employee("alice", "management"), // new Employee("bob", "payroll")); } }
This RESTful web controller can be described as follows:
@RestController
: Spring Web’s annotation to indicate that this controller involves data, not templates...