Skip to main content
PreparationZone Logo
PrepZone

RestClient vs WebClient vs RestTemplate

Three HTTP clients, when to use each, and @HttpExchange declarative clients.

Pass checkpoint below

Why this matters

  • RestTemplate is deprecated — it blocks a thread for every outbound call and lacks a fluent API.
  • RestClient (Boot 3.2+) is the modern blocking client: fluent, composable, and works with virtual threads.
  • WebClient is the reactive non-blocking option; use it when the calling code is already on WebFlux or you need streaming responses.

RestClient (Boot 3.2+)

L1 · Fresher

Fluent synchronous HTTP client replacing RestTemplate for blocking calls to payment APIs.

WebClient

L2 · Intermediate

Non-blocking client for reactive stacks or when integrating with async pipelines.

@HttpExchange interfaces

L3 · Advanced

Declarative clients similar to Feign — define interface methods mapped to remote REST operations.

Timeouts and retries

L4 · Expert

Configure connect/read timeouts and Resilience4j retries — never use unbounded defaults in production.

Platform threads (carriers)
VT-1Blocked on I/O
VT-2Running
VT-3Blocked on I/O

Blocked virtual threads release their carrier — other virtual threads continue

Thousands of virtual threads multiplex onto a small pool of platform (carrier) threads.

Three HTTP clients at a glance

  • RestTemplate — synchronous, blocking, deprecated since Spring 6. Do not start new code with it.
  • RestClient — synchronous, blocking, fluent builder API. Default choice for MVC apps on Boot 3.2+.
  • WebClient — reactive, non-blocking, returns Mono/Flux. Pairs with WebFlux or fire-and-forget async.
  • @HttpExchange — declarative interface backed by RestClient or WebClient via HttpServiceProxyFactory.
  • Observation — all three integrate with Micrometer tracing when observation is enabled.

RestClient — the modern blocking client

Java
// learn:fragment
@Configuration
public class HttpClientConfig {

    @Bean
    public RestClient inventoryRestClient(RestClient.Builder builder) {
        return builder
                .baseUrl("http://inventory-service:8081")
                .defaultHeader("X-Service-Name", "bookstore-api")
                .build();
    }
}

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • WebClient — reactive outbound calls
  • Declarative clients with @HttpExchange

Test yourself

Answer these before moving on — recall is what makes it stick.