Skip to content

Instantly share code, notes, and snippets.

View Francesco-itembase's full-sized avatar

Francesco-itembase

View GitHub Profile
Long itemId = 42L;
BigDecimal vatRate = BigDecimal.of(0.42);
// error handling is omitted for brevity
return fetchItem(itemId)
.flatmap(item -> calculateTax(item, vatRate))
.flatmap(BusinessClass::writeTaxToDB);
@Francesco-itembase
Francesco-itembase / webflux.java
Created June 29, 2020 07:51
Small webflux application
// AppRouter.java
@Configuration
public class AppRouter {
// works for a single bean
@Bean
public RouterFunction<ServerResponse> routes(ResouceHandler resourceHandler) {
return RouterFunctions.route(GET("/resource/{id}").and(accept(APPLICATION_JSON)), resourceHandler::get)
.andRoute(GET("/resource/filter/{filterQuery}").and(accept(APPLICATION_JSON)), resourceHandler::getFiltered);
}
}