Coder Social home page Coder Social logo

waqi-js-client's Introduction

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);

Replace 'YOUR_API_KEY' with the actual API key you already obtained from above.

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);
  });

waqi-js-client's People

Contributors

kingdageek avatar niyiomotoso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.