Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
}
}
// AppHandler.java
@Component
public class BookHandler {
private final AppService appService;
public BookHandler(AppService appService) {
this.appService = appService;
}
public Mono<ServerResponse> get(ServerRequest request) {
String id = request.pathVariable("id");
return ok()
.contentType(MediaType.APPLICATION_JSON)
.body(appService.getById(id), AppModel.class);
}
}
// AppRepository.java
public interface AppRepository extends ReactiveCrudRepository<AppModel, String> {
Mono<AppModel> findById(Mono<String> id);
@Query("{ 'filter': ?0 }")
Flux<AppModel> findByFilter(String filter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment