DEV Community

NewsData.io
NewsData.io

Posted on

How To Fetch Real-Time News Using NewsData.io?

If you are building a news app, a dashboard, or a side project that requires fresh headlines, you don’t need to rely on a web scraper or aggregator. News APIs such as NewsData.io give you a simple API that hands you real-time news from thousands of sources around the world, already structured and ready to use.

In this guide, we’ve covered how you can fetch real-time news data using NewsData.io.

1. Create a free NewsData.io Account

Head over to NewsData.io and register for a free account. It only takes a few minutes, and no credit card is required for the free plan. Once you’ve created the account, go to your dashboard - you’ll find your API key sitting right there. Keep this key handy; it’s what authenticates every request you make.

2. Understand the Main Endpoint

NewsData.io offers a few different endpoints, but the one you’ll use for real-time news is:
https://newsdata.io/api/1/latest

This endpoint returns the most recent articles published across the web, with updates delivered continuously. Think of it as a live feed you can query anytime.

3. Make Your First Request

You don’t need any fancy setup to test the API. A simple browser URL or a curl command will do:
curl "https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY"

Swap YOUR_API_KEY with the key from your dashboard, run it, and you’ll get back a JSON response packed with recent articles - titles, descriptions, source names, publish dates, links, etc.

4. Install Python (if you haven’t already)

If you want to follow along with the Python example below, you’ll need Python installed on your system first. Here’s a quick guide:

Windows/Mac: Go to python.org/downloads and download the latest version. Run the installer, and on Windows, make sure you check the box that says "Add Python to PATH" before clicking install.

Mac (alternative): If you use Homebrew, just run brew install python in your terminal.

Linux: Most distros come with Python pre-installed. If not, run sudo apt install python3 (Ubuntu/Debian) or the equivalent for your package manager.

Confirm it worked by typing python --version in your terminal — you should see something like

Python 3.12.0
Enter fullscreen mode Exit fullscreen mode

Next, install the requests library, which makes calling APIs in Python much easier:
pip install requests

NewsData.io also offers an official Python SDK: pip install newsdataapi. But plain requests is simpler to follow if you are new to APIs.

5. Fetch News in Your Code (Python Example)

For most projects, you’ll want to pull this data inside your app rather than the terminal. Here’s a beginner-friendly Python example using the requests library:

import requests

API_KEY = "YOUR_API_KEY"
url = "https://newsdata.io/api/1/latest"

params = {
    "apikey": API_KEY,
    "language": "en"
}

response = requests.get(url, params=params)
data = response.json()

for article in data["results"]:
    print(article["title"])
    print(article["link"])
    print("---")
Enter fullscreen mode Exit fullscreen mode

This script retrieves the latest English-language news and prints each headline with its link. That’s it; no need for any complicated setup, no scraping logic, just clean JSON ready to use.

If you’re working in JavaScript instead, the same idea applies using fetch:

fetch(`https://newsdata.io/api/1/latest?apikey=YOUR_API_KEY&language=en`)
  .then(res => res.json())
  .then(data => {
    data.results.forEach(article => {
      console.log(article.title, article.link);
    });
  });
Enter fullscreen mode Exit fullscreen mode

6. Narrow Down Results with Filter

One of the best parts of NewsData.io is how easily you can filter the news feed to match exactly what you need. Here are some handy parameters:

country - get news from a specific country (e.g., us, jp, in)
category - filter by topic like technology, business, sports, or health
q - search for a keyword, like "AI" or "climate change"
language - limit results to a specific language

For example, if you want the latest technology news from Japan:

https://newsdata.io/api/1/latest?
apikey=YOUR_API_KEY&country=jp&category=technology
Enter fullscreen mode Exit fullscreen mode

This kind of filtering means you are not stuck sorting through irrelevant articles for the content that you actually need. Instead, you get exactly the slice of news your app needs.

7. Keep Your Data Fresh with Polling

Since the API reflects real-time updates, many developers set up their app to call the endpoint every few minutes (or based on your plan’s rate limits) to keep headlines fresh. A simple approach is to run the request on a timer or a scheduled job, then update your frontend whenever a new article comes in.

Just be mindful of your plan’s request limits; the free tier is great for testing and small projects, but if you’re building something with heavier traffic, it’s worth checking NewsData.io paid tiers for higher limits.

8. Handle Errors Gracefully

Like any API, things can occasionally go wrong - a missing API key, hitting the API rate limit, or a bad parameter. It’s good practice to check the response status before using the data:

if response.status_code == 200:
    data = response.json()
else:
    print("Something went wrong:", response.status_code)
Enter fullscreen mode Exit fullscreen mode

This small habit saves you from confusing bugs down the line.

Wrapping Up

That’s really all it takes to start fetching real-time news into your project with NewsData.io. Sign up, grab your API key, hit the /latest endpoint, and use filters to shape the results however you need. Whether you’re building a news dashboard, a personal project, or something bigger down the line, NewsData.io takes care of the heavy lifting so you can focus on building your app instead of chasing down news sources yourself.

Top comments (0)