Consuming a RESTful API from another Spring Boot application using RestClient
In this recipe, we’ll use a new component introduced in Spring Framework 6.1 and available in Spring Boot since version 3.2. In the previous recipe, we created a FeignClient by creating an interface in the client application and defining the same methods available in the target service. By using the RestClient component, we will have a fluent API that offers an abstraction over HTTP libraries. It allows converting from Java objects to HTTP requests, and the other way round, the creation of objects from the HTTP responses.
Getting ready
We will enhance the RESTful API created in the Using OpenAPI to document our RESTful API recipe. If you haven’t completed it yet, you can find a working version in the book’s GitHub repo at https://github.com/PacktPublishing/Spring-Boot-3.0-Cookbook.
You can find the code to start this exercise in the chapter1/recipe1-7/start
folder.
We will...