RxJava applies the ReactiveX programming model to Java and integrates with Spring WebFlux through asynchronous, event-oriented return types. WebFlux controllers can return Observable, Single, Completable, or Flowable instead of ordinary values or Reactor types. section 12.1.2
Common controller mappings include:
- Return Observable<Taco> for a sequence, such as recent tacos supplied by a service. section 12.1.2
- Return Single<Taco> for a single lookup, paralleling Reactor's Mono. section 12.1.2
- Use Completable for no-value completion or Flowable as an alternative to Observable. section 12.1.2
Reactive taco lookup
A controller can delegate an identifier lookup to a service and return the result directly: `public Single<Taco> tacoById(@PathVariable("id") Long id) { return tacoService.lookupTaco(id); }`. section 12.1.2
@GetMapping(params = "recent")
public Observable<Taco> recentTacos() {
return tacoService.getRecentTacos();
}
Browse a complete controller method returning an RxJava Observable for recent results. section 12.1.2
