When one backend needs data or action from another, it can call that service’s REST endpoint. RestClient is Spring’s direct, synchronous HTTP client: send a request and wait for the response. section 11.0 section 11.1
A typical call passes through these steps:
- Create a RestClient with the remote service’s base URL. section 11.2
- Choose an HTTP method and endpoint, then add headers and a request body if needed. section 11.2
- Retrieve the response and map its body to a Java type. section 11.2
Forwarding a payment request
A PaymentsProxy uses RestClient to POST a Payment to /payment, forwards a requestId header, and reads the response as a Payment. A controller delegates to the proxy; calling that controller returns the remote service’s response. section 11.2
RestClient suits common calls in non-reactive applications. OpenFeign can help organize larger, more structured service communication; WebClient is the option for reactive applications and non-blocking calls. section 11.1 section 11.6
