It is possible to call an external API by a web application.
This technique is useful for any applications following monolith but essential for applications following hexagonal and microservices designs.
The server which publishes the public API will get a request and returns a text which is usually an unformatted JSON.
In order to process the JSON process the received String or use a JSON parser before processing.
In microservices architecture, the incoming (frontend) requests arrive to the gateway controller first. This controller calls internal endpoints (microservices) to create data which must be returned to the frontend.
In such model the API calls are essential. In Spring, an internal call is executed via a RestTemplate instance.
In case of using RestTemplate, it is best practice to create a RestTemplate bean and inject that into the gateway controller, instead of creating instances per endpoints. The bean is created in a configuration class.
EXAMPLE FOR API CALL, RECEIVED RESPONSEENTITY VIA RESTTEMPLATE:
EXAMPLE FOR API CALL, RECEIVED A RAW STRING:
EXAMPLE FOR API CALL, RECEIVED JSON: