Extract Live News and Blog Articles using Mediastack API

The Mediastack is a SaaS platform that provides an easy to use API to get live news and blog articles in the form of JSON API. The Mediastack platform provides the developer an easy-to-use, fast, and scalable news extraction platform.

mediastack homepage

Mediastack provides the following features:

  • Easy to use API.
  • Lighting fast API response.
  • Global news coverage.
  • 7500+ sources in 50 countries.
  • Historical news data with headlines.
  • Free plan and affordable premium plans.

How to use Mediastack API

To use Mediastack news extraction API, you need to create an account on Mediastack and obtain an API token key.

You can simply navigate to the signup page and create a new free account.

mediastack pricing

Once you have created your account, Mediastack will send an email to your account to verify your address. Once your email address is verified, Mediastack will generate an API key for you. Make sure that you don’t share it with unauthorized users.
Let’s call a simple API to observe how it works. Here is a CURL command to crawl and extract HTML from the homepage of our website.

curl "http://api.mediastack.com/v1/news?access_key=YOUR_API_KEY&symbols=AAPL"

Once you hit the request, Mediastack will extract the news from the source mentioned in the API call and return the response. Simple as that.

Integrating with Node.js

Here is a sample code to Integrate Mediastack API with Node.js.

Create a new Node project.

npm init --y

Install axios node module.

npm install --save axios

Replace the apikey variable with your own API key.

const axios = require('axios');
const params = {
  symbols: 'AAPL', // example source
  access_key: 'YOUR_API_KEY'
}

axios.get('http://api.mediastack.com/v1/news', {params})
  .then(response => {
        const apiResponse = response.data;
        console.log(apiResponse);
  }).catch(error => {
        console.log(error);
  });

Save the file and name it app.js. Run the code using the following command.

node app.js

You should see the following output in the terminal.

mediastack response

Awesome. We made the integration in a minute. This is how easy it is to use Mediastack news extraction API.

This is just the tip of the iceberg, Mediastack provides lots of useful information related to their API’s on the documentation page.

Pankaj Kumar
Pankaj Kumar
Articles: 209