user1409534
user1409534

Reputation: 2304

Mono or Flux request body in WebFlux controller

What is the difference between a controller that gets input regular java payload and that of reactive payload? For example, say I have the following 2 endpoints:

@RestController
public class MyController {
@PostMapping
public Flux<SomeObject> doThing(@RequestBody MyPayload playlod) {
// do things that return flux - reactive all the way from this controller

and this one:

@RestController
public class MyController {
@PostMapping
public Flux<SomeObject> doThing(@RequestBody Mono<MyPayload> playlod) {
   

I don't understand the difference between the 2 methods in reactive point of view.

Upvotes: 8

Views: 4312

Answers (1)

lkatiforis
lkatiforis

Reputation: 6255

According to WebFlux documentation:

The request body can be one of the following way and it will be decoded automatically in both the annotation and the functional programming models:

  • Account account — the account is deserialized without blocking before the controller is invoked.
  • Mono<Account> account — the controller can use the Mono to declare logic to be executed after the account is deserialized.
  • Flux<Account> accounts — input streaming scenario.

Upvotes: 9

Related Questions