← Back to list

Setup Rest Client in Spring boot 3.2

I could find a lot of tutorials about implementing Feigh Client, WebClient, or even the old library RestTemplate, but a few of RestClient…

Victor Rojas Barboza · 2024-04-13 21:09 · 9 claps · 0.7 min read
#spring-boot #rest-api #rest-client #java
Open on Medium ↗
Wiki topics: 📚 · Books & Reading

Setup Rest Client in Spring Boot 3.2

I could find a lot of tutorials about implementing Feigh Client, WebClient, or even the old library RestTemplate, but a few of RestClient. Spring boot team advice to migrate RestTemplate to RestClient or WebClient.

  1. Required dependencies

We don’t need to add any dependency to use RestClient because is part of the spring-webmvc module, it’s included in the web starter

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>
  1. Create a Bean for setting up the Rest client properties
@Configuration
@EnableConfigurationProperties(value = FooProviderApplicationProperties.class)
public class FooApiConfig {

  @Bean
  FooApiConfigApi fooApiConfigApi() {
    RestClient client = RestClient.create("Url");
    HttpServiceProxyFactory factory = HttpServiceProxyFactory
      .builderFor(RestClientAdapter.create(client))
      .build();
    return factory.createClient(CredentialAccessApi.class);
  }

}
  1. Declare the Rest third Api contracts using interfaces
@HttpExchange(accept = "application/json", contentType = "application/json")
public interface FooApi{

    @PostExchange(contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    ResponseEntity<AzureAuthResponse> getToken(@RequestBody MultiValueMap<String, String> parameters);

    @DeleteExchange("/foo")
    ResponseEntity<FooResponse> deleteCredentials(@RequestParam("paramx") String paramx,
                                            @RequestParam("paramy") String paramy);

    @PostExchange("/boo")
    ResponseEntity<BooResponse> save(@RequestBody BooRequest request);

}
  1. Implement the interfaces
@Slf4j
@Component
public class FooApiAdapter implements FooApiPort {
    private final FooApi fooApi;

    public FooApiAdapter(FooApi fooApi) {
        this.fooApi = fooApi;
   }

    @Override
    public void doSomenthig() {
        ...
    }

메타데이터
post_id
2faef8f22147
slug
setup-rest-client-in-spring-boot-3-2-2faef8f22147
url
https://medium.com/@vjrojasb/setup-rest-client-in-spring-boot-3-2-2faef8f22147
canonical_url
https://medium.com/@vjrojasb/setup-rest-client-in-spring-boot-3-2-2faef8f22147
author_url
https://medium.com/@vjrojasb
status
ok
fetched_at
2026-07-24 01:50:55