DEV Community

Harsh Vardhan Goswami
Harsh Vardhan Goswami

Posted on

How i built a COVID-19 News Restful API

Hello beautiful people this is me harsh. I created a COVID-19 news Restful API using python flask and beautiful soap. I named it CORONEWS-19 API and it also got its own website and documentation.

Why i built it?

I created a website called with my friend Roshan Chokshi and in our website we have a news section where we display the COVID-19 news so we were using newsapi and that api has a limit of hits per user and all that free and paid service shit so i just came up with a idea that why not create our own api for delivering COVID-19 news. So i just opened Atom(Text Edito) i personally use and started building it and now i will explain how.

How i built it?

So this CORONEWS-19 API is built on top of flask(python framework for making web apps) and beautiful soup and now you guys be thinking that from where you getting news so thats where beautiful soup comes in. Building of this API includes few stages.

1.Gathering the data.
2.Structuring the data.
3.Providing the data as response to request.

Lets talk about how i got the news data.

So, for this task i have used beautiful soup to scrap news websites to gather the news it's kind a illegal thing to scrap any website without permission but hey we can give it a shot. From every website i have gathered news article title, feature image, link to the article.

Now it's time to structure the data we have got from beautiful soup.

So, as i have mentioned above that i have scraped news website so its time to arrange the data in a proper manner so for this i took a empty list and then i appended every news article i got from beautiful soup in a dictionary format with title,img,link of the article the output was something like this:

            "title":"President Trump Expands Role Of US Army In Fight Against Coronavirus Pandemic"
            "title":"China observes national mourning day for COVID-19 victims"

Now we got the data now its time to ready it for the users of the API.

For this task i choose flask and i created a python function which has all the code inside which at last returns the list of news articles and then i initialized a flask app and set an route '/' to a class which gives a list in form of json using flask function called jsonify. Those who wanna read the code here you go.

from flask import Flask
app = Flask(__name__)

def articles():
    return news

This is how i made this API and now its time to host this api somewhere so that people can use it in their projects. So i choosed heroku for this task because it supports server based web apps and also its free to some extent.

You can see the response of this API by visiting this link Click Here.
You can read the small documentation of this api here

Thanks for reading this post ❤️. I really appreciate it man and you can also read my own blog website Electron Blog. With that being said this is me harsh and i am signing out and i will catch you guys in my next one.

Top comments (2)

msamgan profile image
Mohammed Samgan Khan

nice efforts bhai..

electronlab profile image
Harsh Vardhan Goswami

Thanks a lot man🖐️🖐️