Was this helpful?

The Apigee SDKs work by making RESTful API calls from your application to the App Services API. In some cases, both synchronous and asynchronous calls are supported for most methods, as in the case of the Apigee Android SDK, while in others only asynchronous calls are supported, as in the Apigee JavaScript SDK. The following is a brief explanation of synchronous vs. asynchronous API calls.

Synchronous

If an API call is synchronous, it means that code execution will block (or wait) for the API call to return before continuing. This means that until a response is returned by the API, your application will not execute any further, which could be perceived by the user as latency or performance lag in your app. Making an API call synchronously can be beneficial, however, if there if code in your app that will only execute properly once the API response is received.

Asynchronous

Asynchronous calls do not block (or wait) for the API call to return from the server. Execution continues on in your program, and when the call returns from the server, a "callback" function is executed. For example, in the following code using the Apigee JavScript SDK, the function called dogCreateCallback will be called when the create dog API call returns from the server. Meanwhile, execution will continue:

function dogCreateCallback(err, dog) {
	alert('I will probably be called second');
	if (err) {
		//Error - Dog not created
	} else {
		//Success - Dog was created

	}
}

client.createEntity({type:'dogs'}, dogCreateCallback);
alert('I will probably be called first');

The result of this is that we cannot guarantee the order of the two alert statements. Most likely, the alert right after the createEntity function call will be called first since the API call will take a second or so to complete.

The important point is that program execution will continue, and asynchronously, the callback function will be called once program execution completes.

Add new comment

Provide your email address if you wish to be contacted offline about your comment.
We will not display your email address as part of your comment.

We'd love your feedback and perspective! Please be as specific as possible.
Type the characters you see in this picture. (verify using audio)

Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.