Quick Start
Get started with NewsDataHub API in minutes. This guide will walk you through making your first API request and exploring what you can build.
Getting Started
Section titled “Getting Started”1. Get Your API Key
Section titled “1. Get Your API Key”Sign up for a free account to get your API key. Free accounts include 100 requests per day with access to the /news endpoint.
2. Make Your First Request
Section titled “2. Make Your First Request”Choose your preferred language below and copy the example code. Replace your_api_key_here with your actual API key.
3. Explore & Build
Section titled “3. Explore & Build”Dive into the API Reference for complete documentation on all endpoints, parameters, and response formats.
Code Examples
Section titled “Code Examples”Copy and paste these examples to start fetching news data. Each example shows how to get the latest news and search for specific topics.
Install required package:
pip install requestsimport requests
API_KEY = 'your_api_key_here'BASE_URL = 'https://api.newsdatahub.com/v1/news'
headers = { 'X-Api-Key': API_KEY, 'User-Agent': 'docs-quick-start/1.0-py'}
# Get latest newsresponse = requests.get(BASE_URL, headers=headers)data = response.json()print(data)
# Search for specific newsparams = {'q': 'artificial intelligence', 'per_page': 10}response = requests.get(BASE_URL, headers=headers, params=params)data = response.json()print(data)Install required package:
npm install axiosconst axios = require('axios');
const API_KEY = 'your_api_key_here';const BASE_URL = 'https://api.newsdatahub.com/v1/news';
const headers = { 'X-Api-Key': API_KEY, 'User-Agent': 'docs-quick-start/1.0-js'};
// Get latest newsasync function getNews() { try { const response = await axios.get(BASE_URL, { headers }); console.log(response.data); } catch (error) { console.error('Error:', error.message); }}
// Search for specific newsasync function getFilteredNews() { try { const response = await axios.get(BASE_URL, { headers, params: { q: 'artificial intelligence', per_page: 10 } }); console.log(response.data); } catch (error) { console.error('Error:', error.message); }}
getNews();getFilteredNews();# Get latest newscurl -X GET "https://api.newsdatahub.com/v1/news" \ -H "X-Api-Key: your_api_key_here" \ -H "User-Agent: docs-quick-start/1.0-curl"
# Search for specific newscurl -X GET "https://api.newsdatahub.com/v1/news?q=artificial%20intelligence&per_page=10" \ -H "X-Api-Key: your_api_key_here" \ -H "User-Agent: docs-quick-start/1.0-curl"package main
import ( "encoding/json" "fmt" "io/ioutil" "net/http" "net/url")
const ( apiKey = "your_api_key_here" baseURL = "https://api.newsdatahub.com/v1/news")
func main() { client := &http.Client{}
// Get latest news req, err := http.NewRequest("GET", baseURL, nil) if err != nil { fmt.Println("Error creating request:", err) return }
req.Header.Add("X-Api-Key", apiKey) req.Header.Add("User-Agent", "docs-quick-start/1.0-go")
resp, err := client.Do(req) if err != nil { fmt.Println("Error making request:", err) return } defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body))
// Search for specific news params := url.Values{} params.Add("q", "artificial intelligence") params.Add("per_page", "10")
reqWithParams, _ := http.NewRequest("GET", baseURL+"?"+params.Encode(), nil) reqWithParams.Header.Add("X-Api-Key", apiKey) reqWithParams.Header.Add("User-Agent", "docs-quick-start/1.0-go")
resp2, _ := client.Do(reqWithParams) defer resp2.Body.Close()
body2, _ := ioutil.ReadAll(resp2.Body) fmt.Println(string(body2))}require 'net/http'require 'json'require 'uri'
API_KEY = 'your_api_key_here'BASE_URL = 'https://api.newsdatahub.com/v1/news'
# Get latest newsdef get_news uri = URI(BASE_URL) req = Net::HTTP::Get.new(uri) req['X-Api-Key'] = API_KEY req['User-Agent'] = 'docs-quick-start/1.0-rb'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end
puts JSON.parse(response.body)end
# Search for specific newsdef get_filtered_news uri = URI(BASE_URL) params = { q: 'artificial intelligence', per_page: 10 } uri.query = URI.encode_www_form(params)
req = Net::HTTP::Get.new(uri) req['X-Api-Key'] = API_KEY req['User-Agent'] = 'docs-quick-start/1.0-rb'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end
puts JSON.parse(response.body)end
get_newsget_filtered_newsFull Example Project
Section titled “Full Example Project”Want to see a complete implementation? Check out our open-source news aggregator built with the NewsDataHub API.
NewsDataHub News Aggregator
Section titled “NewsDataHub News Aggregator”A modern, full-featured news aggregator application showcasing best practices for integrating the NewsDataHub API. Includes search functionality, filtering, pagination, error handling, and a clean user interface.
Technologies: React • TypeScript • Express • Docker • Demo Mode • Dark Mode
View on GitHub →Next Steps
Section titled “Next Steps”Ready to dive deeper? Here are some suggested next steps:
- Explore API Reference - Learn about all available endpoints, parameters, and response formats
- Advanced Filtering - Master search queries, boolean operators, and filtering options