Rest Clients
Rest Template
- Used to make REST API calls. Similar to Axios
- Imported from
org.springframework.web.client.RestTemplate
ResponseEntity<String> responseEntity = new RestTemplate()
.getForEntity(
"http://localhost:8000/currency-exchange/from/{from}/to/{to}", String.class,
uriVariables
);
String response = responseEntity.getBody();
Feign
- Creates a proxy which is similar to a Dao
@FeignClient(name = "netflix-zuul-api-gateway-server")
@RibbonClient(name = "currency-exchange-service")
public interface CurrencyExchangeServiceProxy {
// @GetMapping("/currency-exchange/from/{from}/to/{to}")
@GetMapping("/currency-exchange-service/currency-exchange/from/{from}/to/{to}")
public CurrencyConversionBean retrieveExchangeValue(@PathVariable("from") String from, @PathVariable("to") String to);
}
- The proxy is injected into the class and with that rest calls can be easily implemented