Spring: WebClient is reactive and non-blocking

Use it in reactive code; block() in a servlet app works but gives up the benefit and can deadlock on a small pool.

Code
WebClient client = WebClient.create("https://api.example.com");

Mono<Order> mono = client.get()
        .uri("/orders/{id}", 42)
        .retrieve()
        .bodyToMono(Order.class);

// Reactive: return the Mono
// Blocking (servlet stack): Order o = mono.block();
Output
Nothing is sent until the Mono is subscribed to.
A forgotten .subscribe() or .block() means the request never happens at all.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11