Spring: RestClient is the modern synchronous HTTP client

Spring 6.1 introduced it as the replacement for RestTemplate, with a fluent API and the same threading model.

Code
RestClient client = RestClient.create();

Order order = client.get()
        .uri("https://api.example.com/orders/{id}", 42)
        .header("Authorization", "Bearer " + token)
        .retrieve()
        .body(Order.class);

ResponseEntity<Void> created = client.post()
        .uri("https://api.example.com/orders")
        .contentType(MediaType.APPLICATION_JSON)
        .body(request)
        .retrieve()
        .toBodilessEntity();
Output
Order[id=42, sku=JCH-01, qty=2]
201 CREATED
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