API for livecovid.in-webapp which uses data from livecovid.in-api.
The reason why this exists is because I personally own a very teeny tiny server, and it was not able to respond within resonable time limits given the traffic these days. So this is an attempt to not buy more server capacity and save some bucks. (Which I think is inevitable).
This works by using cloudflare workers which is a pretty neat offering from the guys at Cloudflare. What we are essentially doing in this repo is calling the source API(api.livecovid.in) and caching that data to cloudflare's global CDN (KV store, as they call it) for fast access.
To update these caches I am utilizing cron triggers which is another fetaure of cloudflare workers which enables you to run scripts at predefined intervals and update the cache(KV store) if you want to.
To start development..
- Clone the repo to your local machine.
- Setup Wrangler which is the recommended way to deploy workers directly from your command line.
If you are not already familiar with the tool, I recommend that you install the tool and configure it to work with your Cloudflare account. Documentation can be found here.
-
Create a new file
worker.toml
file in the root of the project. Copy the contents fromworker.toml.example
filecp worker.toml.example worker.toml
-
Now since you already have
wrangler
cli installed, use this to get your accountID and add it in thewrangler.toml
file.wrangler whoami
-
Generate KV namespaces using below command and add to your
wrangler.toml
file.wrangler kv:namespace create "YOUR_STORE_NAME" wrangler kv:namespace create "PROD_YOUR_STORE_NAME"
-
Finally you can test it locally using
wrangler dev
-
Once you are ready, you can deploy to a
workers.dev
domain usingwrangler publish
You will see a URL in the output.
This template comes with mocha tests which simply test that the request handler can handle each request method. npm test
will run your tests.
This template uses prettier
to format the project. To invoke, run npm run format
.
For information on how to preview and publish your worker, please see the Wrangler docs.
If you run into issues with this project, please feel free to file an issue here.
If the problem is with Wrangler, please file an issue here.
This is not an official government project. This is not associated in any way with my employer. I am not getting paid to do this. Also, I have no intentions of making money from this. This is created to keep people informed about the current state of Covid-19 in the country. If you need help, please call the emergency numbers listed on the website here or call 100.
If you feel any information is missing or there is any error, please feel free to create an issue or reach out to me directly on Twitter and I would be happy to assist.
This would not have been possible without the awesome guys at https://github.com/covid19india. I was initially scraping the MoHFW website, but then I got to know about them and since then this project internally calls their API. They are doing really awesome work maintaining a crowdsourced database of patients. Thanks to them for all the hard work!
Anand – @anamritraj | https://anandamritraj.in
Distributed under the MIT license. See LICENSE
for more information.