We are trying to replace the Spring RestTemplate from our project because its depreciated So I want to know if that is a good idea to use SAP cloud SDK httpClient as an alternative to Spring RestTemplate.
-
It isn't deprecated, it is in maintance mode. The `RestTemplate` still provides a unified API for different http client libraries. – M. Deinum Apr 19 '23 at 07:28
2 Answers
WebClient is the recommended alternative for RestTemplate. WebClient is part of Spring WebFlux.
NOTE: As of 5.0 this class is in maintenance mode, with only minor requests for changes and bugs to be accepted going forward. Please, consider using the org.springframework.web.reactive.client.WebClient which has a more modern API and supports sync, async, and streaming scenarios.

- 2,660
- 2
- 4
- 16
That depends a bit on your use case.
The direct successor of the RestTemplate would be the WebClient of Spring, as stated in the API Note. So, as a direct migration path this makes absolute sense.
If you are using the BTP Destinations and consume them via the SAP Cloud SDK DestinationAccessor
using the HttpClient exposed by the Cloud SDK would also be a good option.
This will add, for example, credentials automatically for you.
In addition these Destinations can then be used with out OData or OpenAPI clients, without ever touching the HttpClient.
In the end you can go with either of them, or even a combination (e.g. Cloud SDK HttpClient for everything OData/OpenAPI related, WebClient for all manual calls).

- 1,089
- 1
- 8
- 16