AZURE - EASIEST WAY TO CONSUME "COVID-19" DATA
Tags: logicapps, covid19, azure, cloud
Published: 2020-03-28 11:25:16

Novel Corona Virus spreading all across the globe and Many Countries are requesting their citizen to stay at home for months. While everyone is trying to find some kind of things to do to avoid boredom during a lockdown situation, I decided to do something fascinating with Azure.
It was a Saturday afternoon and I was browsing the internet and checking on the count of covid19 cases now and then. While doing this, I found many websites provide JSON format data of  covid19 and they refresh this data every single day. I decided to store this data in my Azure Table  / Cosmos DB for my future projects.
To Store the covid19 data, Code has to  follow the below 7 Steps workflow: 
1. Repeat below Steps  once every Day as those websites provide the latest data once every day 
2. Make HTTP Request 
3. Consume HTTP Response
4. Convert HTTP Response to JSON Object
5. using a loop, Massage each  JSON Document  and Convert it into Model class which represent a row/document in Azure Table/Cosmos DB 
6. Create Connection to Azure Table/Cosmos DB
7. Store the Data 


  As the World is moving towards the "No-Code" trend, I decided to consume this data and store it in Azure Table /Cosmos DB  without writing a single line of code. 
You must be thinking, How it is possible that without writing a single line of code, one can make HTTP Request to a website endpoint, consume Http Response, convert that Response into JSON, Massaging JSON  and finally store in  Azure Table / Azure Cosmos DB?
The answer is the Azure Logic App. Yes!!!  Azure has a fascinating service called Azure Logic App which can create business workflow without writing a single line of code. With the help of Azure Logic App, One can schedule and automate many business processes. For more details on Azure Logic App, You may visit  https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-overview.

Now let me explain  How you can use Azure Logic App to store covid19 data in  Azure Table/ Cosmos DB.

1. create a Logic App in the Azure Portal. https://portal.azure.com/
![Alt text of image](https://i.postimg.cc/G3DZKcCX/step1.png)


2. Open Logic Apps Designer page. here You can create a workflow  ( 7 steps workflow)  with just easy drag and drop.
In the Logic Apps Designer page, We need to collect data once every day and hence We have to select the Recurrence trigger which will be called once every day.
![Alt text of image](https://i.postimg.cc/xdqZzQ5y/step2.png)


3. After selecting the Recurrence Trigger, the Next step is to Call Website Endpoint using "HTTP Action". For Data, I am using  https://opendata.ecdc.europa.eu/covid19/casedistribution/json/ .
![Alt text of image](https://i.postimg.cc/FKqBb6nt/step3.png)

4. Consume Response of Step 3 and Convert it into JSON using Data Operations --> Parse JSON.  
![Alt text of image](https://i.postimg.cc/VNH3GvvV/step5.png) 

5. To Parse JSON, it needs a JSON schema. You don't have to manually write it, just provide sample JSON and it will create the schema for you. 
![Alt text of image](https://i.postimg.cc/mDzK04F2/step7.png)
![Alt text of image](https://i.postimg.cc/L5jw8VTc/step8.png)
![Alt text of image](https://i.postimg.cc/vHdCSp8b/step9.png)
6. As our JSON data contains an array of documents, we need to loop through it, massage it and store it Cosmos.
![Alt text of image](https://i.postimg.cc/Mp94HH7p/step10.png)
![Alt text of image](https://i.postimg.cc/7YMjvmb7/step11.png)

7. Massaging Data: Map your  response JSON to new JSON document  and add "ID" field in the new JSON document
![Alt text of image](https://i.postimg.cc/RZSyvKnY/step12.png)
![Alt text of image](https://i.postimg.cc/QtTnfqRF/step13.png)

8. Connect to Cosmos DB, select Database and container ( table).  Select Modified JSON Document in Document field, provide partition key-value field.
![Alt text of image](https://i.postimg.cc/1X172qQJ/step14.png)
![Alt text of image](https://i.postimg.cc/C5CrgxMY/step15.png)
9. Finally, Run logic App.
![Alt text of image](https://i.postimg.cc/4xXknjjB/run.png)
![Alt text of image](https://i.postimg.cc/tRFMP23f/success.png)

10. Open Cosmos DB To  check that  data  has been stored or not 
![Alt text of image](https://i.postimg.cc/wTXYq941/hurray.png)




 hurray!!!!!!!!! It's working.
![Alt text of image](https://i.postimg.cc/CMs2L8Zk/tenor.gif)




I hope this post will help you. 

<b>Be Safe!! Spread Knowledge, Spread Love but Not Virus </b>

_*Enjoy Azure & Enjoy Cloud Computing !!!!*_