I've been doing WebFlux wrong
I don't know how this started, but I've been using this kind of construction pretty much everywhere.
@GetMapping("/products")
public Mono<ResponseEntity<Flux<Product>>> getProducts() {
Flux<Product> productFlux = products.findAll();
return Mono.just(ResponseEntity.ok(productFlux));
}
It's a case of trying many things until it works, and then keep doing it. I was investigating a non-related bug and came across a much cleaner way of doing things. I thought WebFlux needed the Mono and ResponseEntity to send a proper HTTP response. Turns out it doesn't.
@GetMapping("/products")
public Flux<Product> getProducts() {
return products.findAll();
}
This works just fine.
Cleaning up the rest of the API, I figured out how I got here. One of the first things I built in WebFlux, when I was still learning the basics, were the Auth methods. They actually needed ResponseEntity because they have to add headers and cookies to responses. I took those methods as an example for the rest of the API and basically copied a bad habit.
Read more articles
- Moving towards Cloud storage
- Add event and user statistics
- Refactor Infrastructure
- Add QR code to mobile
- Video support and Scrolling Menu
- Automatic blog updates with Git Webhooks
- Add sliding sidebar menu to mobile home page
- I've been doing WebFlux wrong
- Implement Blog
- Migrating event urls
- Interesting bug
- Dynamic social media badges
- Improving Games and Teams
- Blue Green deployments
- Why I left the big cloud
- Moving from AWS Amplify to Google Firebase
- First version