NewNews API is a RESTful API service that provides up-to-date news articles from various sources around the world. With this API, you can query news articles by category, date, source, and keywords, and integrate real-time news data into your applications.
- Real-time News: Get the latest news articles from trusted sources worldwide.
- Category Filtering: Query news by categories such as technology, sports, business, and more.
- Keyword Search: Search articles based on specific keywords.
- Source Filtering: Filter articles by specific sources or publishers.
- Pagination and Sorting: Handle large sets of data with pagination and sort articles by publication date.
To use the NewNews API, you need:
- An active API key.
- Node.js (for local development and testing).
- Internet connection for making requests to the API.
To set up the NewNews API locally:
-
Clone the Repository:
git clone https://github.com/yourusername/newnews-api.git
-
Navigate to the Project Directory:
cd newnews-api
-
Install Dependencies:
npm install
-
Start the Development Server:
npm start
This will start the API server on
http://localhost:3000
.
- Create a
.env
file in the root directory with the following variables:ReplaceAPI_KEY=your_api_key BASE_URL=http://newsapi.org/v2 PORT=3000
your_api_key
with the API key provided by the NewNews service.
-
URL:
/api/news/latest
-
Method: GET
-
Query Parameters:
category
(optional): Filter articles by category (e.g., technology, sports, business).source
(optional): Specify a news source.page
(optional): Page number for pagination.pageSize
(optional): Number of articles per page.
-
Example Request:
GET /api/news/latest?category=technology&page=1&pageSize=10
-
Example Response:
{ "status": "ok", "totalResults": 100, "articles": [ { "source": { "id": "techcrunch", "name": "TechCrunch" }, "author": "John Doe", "title": "Latest tech trends in 2024", "description": "An overview of the top technology trends for 2024.", "url": "https://techcrunch.com/article", "publishedAt": "2024-09-30T10:00:00Z", "content": "Full article content here..." } ] }
-
URL:
/api/news/search
-
Method: GET
-
Query Parameters:
q
(required): Search term or keyword.from
(optional): Filter articles published after this date.to
(optional): Filter articles published before this date.sortBy
(optional): Sort articles byrelevance
,popularity
, orpublishedAt
.
-
Example Request:
GET /api/news/search?q=climate+change&from=2024-09-01&to=2024-09-30&sortBy=popularity
-
Example Response:
{ "status": "ok", "totalResults": 50, "articles": [ { "source": { "id": "bbc-news", "name": "BBC News" }, "author": "Jane Doe", "title": "Impact of climate change on global weather patterns", "description": "A detailed look into how climate change is affecting weather globally.", "url": "https://bbc.com/article", "publishedAt": "2024-09-15T12:00:00Z", "content": "Full article content here..." } ] }
To authenticate your requests, include your API key in the headers:
GET /api/news/latest HTTP/1.1
Host: localhost:3000
x-api-key: your_api_key
curl -X GET "http://localhost:3000/api/news/latest?category=technology" -H "x-api-key: your_api_key"
const axios = require('axios');
axios.get('http://localhost:3000/api/news/latest', {
headers: { 'x-api-key': 'your_api_key' },
params: { category: 'technology' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));
All errors are returned in the following JSON format:
{
"status": "error",
"code": "error_code",
"message": "Description of the error"
}
401
: Unauthorized - Invalid API key.404
: Not Found - The requested resource does not exist.500
: Internal Server Error - An unexpected error occurred on the server.
We welcome contributions to enhance the NewNews API! Please refer to the CONTRIBUTING.md file for guidelines on how to contribute.
This project is licensed under the MIT License. See the LICENSE file for more details.
If you have any questions, suggestions, or issues, feel free to open an issue or contact us at support@newnews.com.
We would like to thank all contributors and the open-source community for their support! 😊