Using Spring WebFlux for controllers
Controllers are the integration point between the model and resources in a RESTful web service. They act like the glue that binds everything together while taking care of business logic execution and responses. The following Maven starterdependency
needs to be added to enable Spring WebFlux:
<dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> </dependencies>
The preceding dependency
will import the Reactive Stream, Spring, and Netty dependencies to enable the successful writing of Reactive web applications using Spring.
Implementation of controllers
The following is MovieController
, which caters for listing and rating movies:
@RequestMapping("/movies") @RestController class MovieController constructor(val movieService : MovieService) { @GetMapping fun getMovies() : Flux<Movie> { return this...