Skip to content
Branch: master
Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.
apiproxy adding a simple example of an asynchronous javascript callout Jul 25, 2013 added a note about yahoo weather api Jun 13, 2017

Javascript async callout

Note about usage

This sample calls the Yahoo weather API. Since this sample was created, this API began requiring an API key. To execute this sample, you'll need to obtain a key and add it to the JavaScript code in the proxy that calls the API.

Sample use case

Make async callouts where other policies can still process rather than waiting on a response from the callout.


There are two js files, getWeatherData and assembleResponse. The getWeatherData script makes the http requests, and then they are later accessed in assembleResponse. The example js code extracted from these files:

first js:

var paloAlto = httpClient.get('');
context.session['paloAlto'] = paloAlto;

second js:

var exchange = context.session['paloAlto'];
var resp = exchange.getResponse();

You can parameterize the session names and wrap stuff into functions to make the response parsing/assembling a bit more re-usable.

A critical part to understand in this example is that the delay between the 1st and 2nd JS (including any policies and the waitForComplete) should be long enough for all responses to come back.

Set up, deploy, invoke

To deploy, run $ sh

To test, run $ sh

Ask the community

alt text

Copyright © 2015 Apigee Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.