Requesting Data

Requesting Data & Maps

One of the core, and more appealing, features of the Xweather JavaScript SDK is the ability to easily request data from the Xweather Weather API and map imagery from Xweather Raster Maps. With the SDK, you can quickly set up a request, configure it according to your needs and then perform the request to get access to your data with ease.

At its core, there are two types of requests: data and maps.

Creating an AerisWeather instance initialized with your access keys will provide you with convenience entry points to quickly access the primary pieces of functionality within the SDK, such as creating an API data or Xweather Raster Maps image request. The following are the two primary entry points you'll be working with on your AerisWeather instance when making requests:

MethodDescription
api()Returns a new API data request instance that can be configured for a specific endpoint and data request.
map()Returns a new Raster Maps image request instance that can be configured to return a specific image.

Making Data Requests

Data requests are made using an instance of ApiRequest and interact with the Xweather Weather API, so configuration options are similar to those supported by the API if making requests directly. And since you can chain together your request instance's option setters, the syntax remains clean and concise.

The following is a basic data request example demonstrating how easy it is to get the data you need once you're setup with the SDK:

// load the latest observation for Seattle, WA
aeris.api().endpoint('observations').place('seattle,wa').get().then((result) => {
     var data = result.data.ob;
     document.getElementById('obs').innerHTML = `The current weather is ${data.weatherPrimary.toLowerCase()} and ${data.tempF} degrees.`;
});

Refer to the Data Requests documentation for complete details and options when using an ApiRequest instance.

Making Map Requests

Map image requests are made using an instance of MapRequest and interact with Xweather Raster Maps, so configuration options are similar to those supported by the API if making requests directly. And since you can chain together your request instance's option setters, the syntax remains clean and concise.

The following is a basic map image request example demonstrating how easy it is to get the map imagery you need once you've setup:

// load the latest radar image for Seattle, WA at 500x300 pixels
aeris.map().layers('flat,radar,counties,admin').center('seattle,wa').zoom(9).size(500, 300).get().then((result) => {
     // append result image to a DOM target
     document.getElementById('map-target').appendChild(result.image);
     
     // output image valid time to a DOM target
     document.getElementById('map-metadata').innerHTML = `Valid: ${result.metadata.validDate}`;
});

Refer to the Map Requests documentation for complete details and options when using an MapRequest instance.