Javascript
Geoapify lets to send multiple API requests within one call by using Batch service. Learn more about the Batch service on the documentation page.
The Batch service based on asynchronous calls. Here is an implementation of asynchronous calls that can be used for Batch requests from a Javascript project.
Create a batch job and monitor results
We need 2 types requests: HTTP Post request to create a job and HTTP Get request to monitor the job execution and getting result
- As we interested in response status by checking the response, we use
getBodyAndStatus()
that provides both response status and response body. - If when the job is accepted (HTTP 202) we start monitor results with
getAsyncResult()
. To avoid unnecessary calls we set a timeout to 1000ms (60000ms recommended for bigger jobs) and number of maximal attempts. - As soon as results are available, the
getAsyncResult()
promise is resolved.
Check the JSFiddle for the full code.