Mono is a Project Reactor publisher representing an asynchronous computation that emits zero or one item. Reactive endpoints return it when they produce a single value or no value. section 17.1
Distinguish Mono from the surrounding reactive contracts:
- Use Mono for a single result; use Flux for zero or more results. section 17.1
- Treat an endpoint that returns data as a publisher consumed through Reactive Streams. section 17.1
- Compose values with operators such as map instead of immediately extracting them. section 17.2
Returning and transforming a Mono
A controller can return Mono.just("Hello!"). When authentication is supplied as Mono<Authentication>, auth.map(a -> "Hello " + a.getName()) creates a Mono containing the personalized response. section 17.1 section 17.2
Listing 17.3 The HelloController class
@RestController
public class HelloController {
@GetMapping("/hello")
public Mono<String> hello(
Mono<Authentication> auth) { #1
Mono<String> message = #2
auth.map(a -> "Hello " + a.getName());
return message;
}
}
Inspect a controller that receives Mono<Authentication> and maps its authentication value into a response. section 17.2

