/covid-tracking-api

COVID-19 Rest & GraphQL API for US data, using Cloudflare Workers

Primary LanguageJavaScriptApache License 2.0Apache-2.0

👷 Covid Tracking API

A Cloudflare Worker that makes a requests to get the sheet info and then cleans it up a bit and returns an array of values.

Initial Basic API

The default response is JSON. If you'd like CSV just append .csv at the end of the url. For example https://covidtracking.com/api/states.csv

If you want to filter the /api/us/daily you can add a query param like ?state=NY to only show cases in New York. Or ?state=NY&date=20200316 to show the result of a specific date.

GraphQL API

Technical How

Currently each and every request is passed through Netlify to Cloudflare that makes an API request to Google and then cleans it up and decides format before returning results. A minimal cache is configured.

Easy Deploy w/ Wrangler

wrangler

  • Add wrangler.toml file.
  • Get a Google API Key https://console.developers.google.com/
  • Add Google API Key to cloudflare environment with the command wrangler secret put GOOGLE_API_KEY
  • Publish to Cloudflare with the command wrangler publish

Serverless

To deploy using serverless add a serverless.yml file.

Testing locally

Install cloudflare-worker-local

yarn global add cloudflare-work-local yarn global add nodemon wrangler build && cloudflare-worker-local worker/script.js covid.cape.io 3000 wrangler.toml staging

nodemon --watch worker/script.js --signal SIGHUP --exec 'cloudflare-worker-local worker/script.js covid.cape.io 3000'

KV Cache Keys

wrangler kv:key list --binding=COVID --env=staging wrangler kv:key list --binding=COVID --env=production --prefix="/states.json" wrangler kv:key delete --binding=COVID --env=staging "/screenshots" wrangler kv:key delete --binding=COVID --env=production "/press"