chapter eleven
11 Consuming REST endpoints
This chapter covers
- Calling REST endpoints using RestClient
- Calling REST endpoints using Spring Cloud OpenFeign
- Calling REST endpoints using WebClient
REST services are a common way to implement communication between two system components. The client of a web app can call the backend, and so can another backend component.
In a backend solution composed of multiple services, components need to “speak” to exchange data, so when you implement such a service using Spring, you need to know how to call a REST endpoint exposed by another service. For example, the service implementing the delivery capability might need to ask the service managing the invoices to create an invoice for a given order. At the same time, this service might also need to call the warehouse service to adjust the product quantities according to what was shipped (figure 11.1).
Figure 11.1 Often, a backend app needs to act as a client for another backend app and calls exposed REST endpoints to work with specific data.