October 13, 2020
Estimated Post Reading Time ~

COVID-19 Tracker using API calls in India - AEM 6.5.5

In this article, we will see how we can implement a COVID-19 Tracker in AEM Server. I have used the open-source Postman API’s to get the latest State and District wise data.

I have used the below APIs to get the data related to COVID-19 in India
1. State & District wise API to get the data based on State and District.
2. Raw data of Infected people to get details of each and every person got infected due to COVID-19
3. Total State wise Data to get the increase in the cases every day and tested people report in India.

To get the response of one of the API is have used Postman to study and analyze the data and filter out what is required.

API response for Chandigarh using API 1

Data of infected people in India using API 2



Daily cases count response using API 3
This API can be handled in AEM servlet or Java class to get the response in AEM and filter out the data which is required for the implementation to create a dashboard in AEM pages.

I have used the below code snippet to get the response in form of JSON and later fetched the data which was required to be displayed on the dashboard.

HashMap < String, Object > serviceParam = new HashMap < > ();
serviceParam.put(ResourceResolverFactory.SUBSERVICE, "writeSystemUser");

try (CloseableHttpClient httpClient = HttpClients.createDefault(); ResourceResolver resolver = resolverFactory.getServiceResourceResolver(serviceParam)) {

HttpGet getRequest = new HttpGet("https://api.covid19india.org/state_district_wise.json");

/* Headers can be added if accessing other available APIs */

HttpResponse httpResponse = httpClient.execute(getRequest);
} catch {}
We can also implement rapid-api to get more filtered data based on different query parameters. In this API we need to pass some Header parameters like x-rapidapi-host and x-rapidapi-key.

Source: https://aemsimplifiedbynikhil.wordpress.com/2020/08/16/covid-19-tracker-using-api-calls-in-india-aem-6-5-5/


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.