A simple Node.js API for fetching news articles from the GNews API, with caching and Swagger documentation.
- Prerequisites
- Installation
- Usage
- API Endpoints
- Swagger Documentation
- Environment Variables
- Contributing
Before you begin, ensure you have met the following requirements:
- Node.js and npm installed on your machine.
- GNews API key. You can obtain one by signing up on the GNews website: GNews API.
-
Clone this repository:
git clone https://github.com/Ashishjagrawal/newsAPI.git cd newsAPI
-
Install the project dependencies:
npm install
-
Create a
.env
file in the project root directory and set your GNews API key:GNEWS_API_KEY=your-api-key-here PORT=3000
To start the server, run the following command:
npm start
Your API will be accessible at http://localhost:3000
(or your specified port).
-
Fetch N news articles:
- GET
/api/news/:count
- Example:
http://localhost:3000/api/news/10
- GET
-
Get news articles by category:
- GET
/api/news/:category
- Example:
http://localhost:3000/api/news/business
- GET
-
Search for news articles by keywords:
- GET
/api/search
- Example:
http://localhost:3000/api/search?keyword=technology
- GET
For detailed information on each endpoint and their parameters, refer to the Swagger Documentation section.
You can access the Swagger documentation for this API by visiting:
http://localhost:3000/api-docs
The Swagger UI provides an interactive interface for exploring and testing the API endpoints.
GNEWS_API_KEY
: Your GNews API key.PORT
(Optional): Specify the desired port for the server to run (default is 3000).
Contributions are welcome! If you find a bug or have any suggestions, please open an issue or submit a pull request.