Better design for nested REST call in Rest Template

by hades   Last Updated October 19, 2019 19:05 PM - source

I not sure whether this question should be asked here, let me know if it is not.

I have this application where i need to call 3rd party APIs using Java's RestTemplate, first i call Country API, base on the code returned, i call Vehicle API, and so on. I can do this with nested API call, but i am thinking, is there any better design?

The following is just a simple example:

ResponseEntity<Country> countryResponse="https://localhost:8989/api/countries/1",HttpMethod.GET, new HttpEntity<>,Country.class);

Country countryBody=  countryResponse.getBody();

if(countryBody!= null){
    ResponseEntity<Vehicle> vehicleResponse ="https://localhost:8989/api/countries/"+countryBody.getCode()+"/vehicles",HttpMethod.GET, new HttpEntity<>,Vehicle.class);

  ...with the result returned by vehicleResponse, keep nesting...
Tags : java rest spring

Related Questions

dealing with too many DTO / Java

Updated April 16, 2019 12:05 PM

Simple REST API calls using Spring?

Updated April 27, 2015 00:02 AM