JSPM

waqi-js-client

1.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q28734F
  • License MIT

JS client library for the World Air Quality Index (WAQI) APIs. All available API modules are supported - City feed, Geolocalized feed, Search, and Map Queries.

Package Exports

  • waqi-js-client
  • waqi-js-client/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (waqi-js-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

WAQI JavaScript Client

JavaScript client library for the World Air Quality Index (WAQI) APIs. See documentation here. All available API modules are supported - City feed, Geolocalized feed, Search, and Map Queries.

Installation

You can include this package in your JavaScript project using npm or yarn:

npm install waqi-js-client

Get API key

Sign up for an API key here

Making Requests

The primary API class is a factory class that creates objects for each of the API modules, allowing you to make requests to any of them with your desired request parameters. You have to first create an object for it, then access your desired API module via the object. See the code snippets below:

const apiKey = 'YOUR_API_KEY';
const waqiAPI = new API(apiKey);

For City Feed:

const cityFeedEntity = waqiAPI.cityFeed();
cityFeedEntity.setCity("Munich");
cityFeedEntity.fetchItems().then(response => {
    console.log(response);
}).catch(error => {
    console.error(error);
});

For Search:

const searchEntity = waqiAPI.search();
searchEntity.setKeyword("Johannesburg");
searchEntity.fetchItems().then(response => {
    console.log(response);
}).catch(error => {
    console.error(error);
});

For Lat/Lng based Geolocalized feed:

const geoFeedEntity = waqiAPI.geoFeed();
geoFeedEntity.setCoordinates(37.7749, -122.4194);
geoFeedEntity.fetchItems().then(response => {
    console.log(response);
}).catch(error => {
    console.error(error);
});

For IP based Geolocalized feed:

const ipFeedEntity = waqiAPI.ipFeed();
ipFeedEntity.setIP("MY_IP");
ipFeedEntity.fetchItems().then(response => {
    console.log(response);
}).catch(error => {
    console.error(error);
});

For Map Queries:

const mapStationEntity = waqiAPI.mapStation();
mapStationEntity.setMapBounds(40.712, -74.006, 34.052, -118.243);
mapStationEntity.fetchItems().then(response => {
    console.log(response);
}).catch(error => {
    console.error(error);
});

Replace 'YOUR_API_KEY' with your actual API key when using this library.