In my application, I am consuming an API:
localhost:8080/data/date?12-12-2019&&nextBatch=200
.
I need to call this API in a while
loop by updating 'nextBatch', something like nextBatch+=200
, variable until I get a response from the API. When I call API with the updated value I add the response to the list after every call. I need help to call the same API with updated value so that it improves performance? Below is a sample code for the same.
while (checkMoreData) {
ResponseEntity<Data[]> responseEntity = restTemplate
.exchange("localhost:8080/data/date?12-12-2019&&nextBatch=200", HttpMethod.GET, entity, Data[].class);
if (responseEntity.hasBody() && responseEntity.getBody() != null
&& responseEntity.getBody().length > 0) {
entityList.addAll(Arrays.asList(responseEntity.getBody()));
nextBatch+= 200;
} else {
checkMoreData = false;
}