July 2018
Intermediate to advanced
268 pages
7h 36m
English
As detailed previously, we have two approaches, namely functional-based and annotation-based, for implementing a WebFlux application. Annotation-based is similar to Spring MVC, and because of this, we will be using functional-based approach in our sample application:
@Componentpublic class MovieHandler { private final MovieRepository movieRepository; public MovieHandler(MovieRepository movieRepository) { this.movieRepository = movieRepository; } public Mono<ServerResponse> listMovies(ServerRequest request) { // fetch all Movies from repository Flux<Movie> movies = movieRepository.listMovies(); // build response return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON) .body(movies, Movie.class); } //...Other methods ...Read now
Unlock full access