Let's start with a simple HTTP GET. Similar to Spring MVC endpoints, Spring WebFlux supports Flux operations as shown here:
@GetMapping(API_BASE_PATH + "/images") Flux<Image> images() { return Flux.just( new Image("1", "learning-spring-boot-cover.jpg"), new Image("2", "learning-spring-boot-2nd-edition-cover.jpg"), new Image("3", "bazinga.png") ); }
This preceding controller can be described as follows:
- Using the same Flux.just() helper, we return a rather contrived list
- The Spring controller returns a Flux<Image> Reactor type, leaving Spring in charge of properly subscribing to this flow when the time is right
Before we can move forward, we need to define this Image data type like this:
@Data @NoArgsConstructor ...