All Projects → openaq → Openaq Api

openaq / Openaq Api

Licence: other
OpenAQ Platform API

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Openaq Api

2019 Ncov Frontend
🌏 Map, data and timeline of coronavirus (COVID-19)
Stars: ✭ 141 (-1.4%)
Mutual labels:  hacktoberfest
Magick.net
The .NET library for ImageMagick
Stars: ✭ 2,071 (+1348.25%)
Mutual labels:  hacktoberfest
Shimmerswift
A swift implementation of Facebooks shimmer effect.
Stars: ✭ 143 (+0%)
Mutual labels:  hacktoberfest
Ape Ecs
Entity-Component-System library for JavaScript.
Stars: ✭ 137 (-4.2%)
Mutual labels:  hacktoberfest
Vue Pure Lightbox
Very simple lightbox plugin (without any dependencies) for Vuejs 🌅
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Actionsflow
The free Zapier/IFTTT alternative for developers to automate your workflows based on Github actions
Stars: ✭ 2,243 (+1468.53%)
Mutual labels:  hacktoberfest
Kotlin Gradle Plugin Template
🐘 A template to let you started with custom Gradle Plugins + Kotlin in a few seconds
Stars: ✭ 141 (-1.4%)
Mutual labels:  hacktoberfest
Demo Jenkins Config As Code
Demo of Jenkins Configuration-As-Code with Docker and Groovy Hook Scripts
Stars: ✭ 143 (+0%)
Mutual labels:  hacktoberfest
Webpack Require From
Webpack plugin that allows to configure path or URL for fetching dynamic imports
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Ultimate Java Resources
Java programming. All in one Java Resource for learning. Updated every day and up to date. All Algorithms and DS along with Development in Java. Beginner to Advanced. Join the Discord link.
Stars: ✭ 143 (+0%)
Mutual labels:  hacktoberfest
Lacmus
Lacmus is a cross-platform application that helps to find people who are lost in the forest using computer vision and neural networks.
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Tedivms Flask
Flask starter app with celery, bootstrap, and docker environment
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Almond Server
The home server version of Almond
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Python Sc2
A StarCraft II bot api client library for Python 3
Stars: ✭ 141 (-1.4%)
Mutual labels:  hacktoberfest
Core Framework
This repository holds the Open RuneScape Classic game framework
Stars: ✭ 143 (+0%)
Mutual labels:  hacktoberfest
Tmux
🧛🏻‍♂️ Dark theme for tmux
Stars: ✭ 138 (-3.5%)
Mutual labels:  hacktoberfest
Android Password Store
Android application compatible with ZX2C4's Pass command line application
Stars: ✭ 1,912 (+1237.06%)
Mutual labels:  hacktoberfest
Terrafx
A framework for developing multimedia-based applications.
Stars: ✭ 141 (-1.4%)
Mutual labels:  hacktoberfest
Arepl Vscode
program python in real-time
Stars: ✭ 142 (-0.7%)
Mutual labels:  hacktoberfest
Vscode Stylelint
Official Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 141 (-1.4%)
Mutual labels:  hacktoberfest

OpenAQ Platform API

Build Status Slack Chat

Overview

This is the main API for the OpenAQ project.

Starting with index.js, there is a web-accessible API that provides endpoints to query the air quality measurements. Documentation can be found at https://docs.openaq.org/.

openaq-fetch takes care of fetching new data and inserting into the database. Data format is explained in openaq-data-format.

Getting started

Install prerequisites:

Clone this repository locally (see these instructions) and activate the required Node.js version with:

nvm install

The last step can be skipped if the local Node.js version matches the one defined at .nvmrc.

Install module dependencies:

npm install

Development

Initialize development database:

npm run init-dev-db

This task will start a PostgreSQL container as daemon, run migrations and seed data. Each of these tasks is available to be run independently, please refer to package.json to learn the options.

After initialization is finished, start the development server:

npm run dev

Access http://localhost:3004.

Stop database container after finishing:

npm run stop-dev-db

Testing

Initialize test database:

npm run init-test-db

This task will start a PostgreSQL container as daemon, run migrations and seed data. After initialization is finished, run tests:

npm run test

Stop database container after finishing:

npm run stop-test-db

Deploying to production

The server needs to fetch data about locations and cities in the measurement history using AWS Athena. This service must be configured via the following environment variables:

  • ATHENA_ACCESS_KEY_ID: an AWS Access Key that has permissions to create Athena Queries and store them in S3;
  • ATHENA_SECRET_ACCESS_KEY: the corresponding secret;
  • ATHENA_OUTPUT_BUCKET: S3 location (in the form of s3://bucket/folder) where the results of the Athena queries should be stored before caching them;
  • ATHENA_FETCHES_TABLE: the name of the table registered in AWS Athena.

Automatic Athena synchronization is disabled by default. It can be enabled by setting the environment variable ATHENA_SYNC_ENABLED to true. The sync interval can be set using ATHENA_SYNC_INTERVAL variable, in miliseconds. The default interval is set in file config/default.json.

If needed, the synchronization can be fired manually. First, the WEBHOOK_KEY variable must be set to allow access webhooks endpoint. Sending a POST request to /v1/webhooks, including the parameters key=<WEBHOOK_KEY> and action=ATHENA_SYNC, will start a sync run. An example with curl:

curl --data "key=123&action=ATHENA_SYNC" https://localhost:3004/v1/webhooks

Other environment variables available:

Name Description Default
API_URL Base API URL after deployment http://:3004
NEW_RELIC_LICENSE_KEY New Relic API key for system monitoring not set
WEBHOOK_KEY Secret key to interact with openaq-api '123'
USE_REDIS Use Redis for caching? not set (so not used)
USE_ATHENA Use AWS Athena for aggregations? not set (so not used)
REDIS_URL Redis instance URL redis://localhost:6379
DO_NOT_UPDATE_CACHE Ignore updating cache, but still use older cached results. not set
AGGREGATION_REFRESH_PERIOD How long to wait before refreshing cached aggregations? (in ms) 45 minutes
REQUEST_LIMIT Max number of items that can be requested at one time. 10000
UPLOADS_ENCRYPTION_KEY Key used to encrypt upload token for /upload in database. 'not_secure'
S3_UPLOAD_BUCKET The bucket to upload external files to for /upload. not set

AWS Athena for aggregations

The Athena table is fetches_realtime that represents the fetches from openaq-data and has the following schema:

CREATE EXTERNAL TABLE fetches.fetches_realtime (
  date struct<utc:string,local:string>,
  parameter string,
  location string,
  value float,
  unit string,
  city string,
  attribution array<struct<name:string,url:string>>,
  averagingPeriod struct<unit:string,value:float>,
  coordinates struct<latitude:float,longitude:float>,
  country string,
  sourceName string,
  sourceType string,
  mobile string
 )
 ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
 LOCATION 's3://EXAMPLE_BUCKET'

Uploads & Generating S3 presigned URLs

Via an undocumented /upload endpoint, there is the ability to generate presigned S3 PUT URLs so that external clients can authenticate using tokens stored in the database and upload data to be ingested by openaq-fetch. There is a small utility file called encrypt.js that you can use like UPLOADS_ENCRYPTION_KEY=foo node index.js your_token_here to generate encrypted tokens to be manually stored in database.

Dockerfile

There is a Dockerfile included that will turn the project into a Docker container. The container can be found here and is currently mostly used for deployment purposes for AWS ECS. If someone wanted to make it better for local development, that'd be a great PR!

Contributing

There are a lot of ways to contribute to this project, more details can be found in the contributing guide.

Projects using the API

  • openaq-browser site | code - A simple browser to provide a graphical interface to the data.
  • openaq code - An isomorphic Javascript wrapper for the API
  • py-openaq code - A Python wrapper for the API
  • ropenaq code - An R package for the API

For more projects that are using OpenAQ API, checkout the OpenAQ.org Community page.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].