liveBook · Manning

RestClient

As explained in Spring Start Here, Second Edition

RestClient is Spring's synchronous HTTP client for sending requests and waiting for responses from remote services.

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

How Spring Start Here, Second Edition covers it

How deep it goes
Works through client creation, request construction, response retrieval, and a payment example without detailing client internals.
Examples
Demonstrates a payment proxy that forwards a POST request and returns the remote service’s response.
What you can do after
Apply RestClient to send an HTTP request with a URI, headers, and body, then map the response body to a Java type.
How it connects
Connects REST endpoint calls with proxy classes and contrasts RestClient with OpenFeign, WebClient, and RestTemplate.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.