Your application needs data from an external REST API. How would you use RestTemplate or WebClient to consume it in Spring Boot?

RestTemplate and WebClient are the two main options for consuming an external REST API from Spring Boot -- RestTemplate is the classic, blocking client, and WebClient is the modern, non-blocking, reactive client.

Key Points

Example

Fetching a user profile from an external service with RestTemplate returns a UserDto directly, while the same call with WebClient returns a Mono<UserDto> that you subscribe to or map further downstream.

// RestTemplate
UserDto user = restTemplate.getForObject("/api/users/{id}", UserDto.class, id);

// WebClient
Mono<UserDto> user = webClient.get()
        .uri("/api/users/{id}", id)
        .retrieve()
        .bodyToMono(UserDto.class);

Interview Tip

A concise interview answer is

For a blocking call I'd define a RestTemplate bean and use getForObject() or exchange(). For a non-blocking, reactive flow I'd use WebClient, chaining get().uri().retrieve() and mapping the result with bodyToMono() or bodyToFlux(). Since RestTemplate is in maintenance mode, I'd default to WebClient for new code.

Last updated: 11 November 2026

Next question: Your Spring Boot backend needs to accept cross-origin requests from a specific frontend domain. Explain how you would configure CORS policies in your application.

More Spring Boot - Level III (Scenario Based) interview questions

All Spring Boot - Level III (Scenario Based) questions