Javascript Client Example

A quick example of calling the Altitude Angel APIs from a JavaScript client

The easiest way to call our APIs from JavaScript is using jQuery. This is not intended as a tutorial on jQuery but serves as a quick sample reference on making requests against our APIs.

Using the multiple requests method is recommended if calls to other systems using ajax are not made in your client application.

If your application may make calls to other systems then it's recommended to pass the required headers explicitly on each request to prevent leakage of your API keys and device IDs to other sites.

Single Request Using API Keys

// Make a request sending the API key and a device ID header
$.ajax({
    url: 'https://api.altitudeangel.com/v2/mapdata/geojson...',
    headers: {
        'Authorization': 'X-AA-ApiKey YOUR_API_KEY',
        'X-AA-DeviceId': 'yourdeviceId'
    }
})
.done(function(data){
    // process the response ....
    // e.g. if(data.isCompleteData){ ... }
});

Multiple Requests Using API Keys

To save having to specify the API key (and/or device ID) headers per request, they can be defined once:

// Make a request sending the API key and a device ID header
$.ajax({
    url: 'https://api.altitudeangel.com/v2/mapdata/geojson...',
    headers: {
        'Authorization': 'X-AA-ApiKey YOUR_API_KEY',
        'X-AA-DeviceId': 'yourdeviceId'
    }
})
.done(function(data){
    // process the response ....
    // e.g. if(data.isCompleteData){ ... }
});

// Don't need to specify the headers as the setup applies them to all requests
$.getJSON('https://api.altitudeangel.com/v2/mapdata/geojson...')
    .done(function(data){
        // Handle the response here
});

What’s Next

Get started by quickly plotting hazard information on a map of your choice!