Benefits of having HTTP endpoints return Flux/Mono instances instead of DTOs [closed] Benefits of having HTTP endpoints return Flux/Mono instances instead of DTOs [closed] spring spring

Benefits of having HTTP endpoints return Flux/Mono instances instead of DTOs [closed]


I highly suggest you watch the recently presented in Devoxx Belgium "Reactive Web Application with Spring 5" by Rossen Stoyanchev.

In there he talks about how the Reactive Web Controller (presented below) on the surface looks like Spring MVC HTTP Servlet Request/Response Controller but it's actually not

@GetMapping("/users/{id}")public Mono<User> getUser(@PathValiable Long id) {   return this.userRepository.findById(id);}@GetMapping("/users")public Flux<User> getUsers() {   return this.userRepository.findAll();}

he talks about how Servlet 3.1 although non-blocking doesn't truely work for fully reactive and how the glue code connecting the Servlet 3.1 and Reactive Streams is implemented as part of the Spring 5 changes for the Servlet 3.1 compliant web containers (Jetty and Tomcat).

And of course he is touching on fully Reactive non-blocking compliant servers (Netty, Undertow) are supported to run Reactive Streams.


It's not right to mean that Netty is better than tomcat. The implementation is different. Tomcat uses java NIO to implement servlet 3.1 spec. Meantime, netty uses NIO as well but introduces custom api.If you want to get insight in how does servlet 3.1 implemeted in Netty, watch this video https://youtu.be/uGXsnB2S_vc