News Aggregator API: A RESTful API for a personalized news aggregator using Node.js, Express.js, bcrypt, and JWT and api best practices. Redis is used to cache api requests.
- User Module
- News Module
- Node.js
- Express.js
- Joi (Validation)
- JwtToken
- Axios
- Redis
-
Clone the Repository
git clone https://github.com/airtribe-projects/news-aggregator-api-charanjsingh29.git
-
Install Dependencies
$ npm install $ npm run dev
-
New user signup
POST /users/signup
- Request Body:
{ "name": "Clark Kent", "email": "[email protected]", "password": "123456", "preferences":["movies", "comics"] }
- Response:
{ "success": true, "message": "User created successfully", "data": { "id": 1, "name": "Clark Kent", "email": "[email protected]", "preferences": [ "movies", "comics" ] } }
- All fields are required
-
Login
POST /users/login
- Request Body:
{ "email": "[email protected]", "password": "123456", }
- Response:
{ "success": true, "message": "User logged in successfully", "token": "" "data": { "id": 1, "name": "Clark Kent", "email": "[email protected]", "preferences": [ "movies", "comics" ] } }
- All fields are required
-
Logged in user profile
GET /users/profile
- Header
Authorization: Bearer `<your_token>`
- Response:
{ "data": { "id": 1, "name": "Clark Kent", "email": "[email protected]", "preferences": [ "movies", "comics" ] } }
-
Update logged in user profile
PUT /users/profile
- Header
Authorization: Bearer `<your_token>`
- Request Body:
{ "name": "Clark Kent 2" }
- Response:
{ "success": true, "message": "Profile updated successfully", "data": { "user": { "id": 1, "name": "Clark Kent 2", "email": "[email protected]", "preferences": [ "movies", "comics" ] } } }
- All fields are required
-
Get user preferences
GET /users/preferences
- Header
Authorization: Bearer `<your_token>`
- Response:
{ "preferences": [ "movies", "comics" ] }
-
Update user preferences
PUT /users/preferences
- Header
Authorization: Bearer `<your_token>`
- Request Body:
{ "preferences": [ "movies", "comics", "games" ] }
- Response:
{ "success": true, "message": "User preferences updated successfully", "preferences": [ "movies", "comics", "games" ] }
- All fields are required
-
Change password
PUT /users/change_password
- Header
Authorization: Bearer `<your_token>`
- Request Body:
{ "current_password": "Krypt()n8", "new_password" : "test" }
- Response:
{ "success": true, "message": "User password changed successfully", "data": { "user": { "id": 1, "name": "Clark Kent 2", "email": "[email protected]", "preferences": [ "movies", "comics", "games" ] } } }
- All fields are required
- Fetch News
GET /news
- Header
Authorization: Bearer `<your_token>`
- Response:
{ "success": true, "total_results": 1, "news": [ { "source": { "id": "cnn", "name": "CNN" }, "author": "John Towfighi", "title": "Stocks tumble following blowout jobs report - CNN", "description": "US stocks slid Friday as investors digested a better-than-expected jobs report that soured expectations of future rate cuts from the Federal Reserve.", "url": "https://www.cnn.com/2025/01/10/investing/us-markets-jobs-report/index.html", "urlToImage": "https://media.cnn.com/api/v1/images/stellar/prod/gettyimages-2192142491.jpg?c=16x9&q=w_800,c_fill", "publishedAt": "2025-01-10T18:21:40Z", "content": "US stocks slid Friday as investors digested a better-than-expected jobs report that soured expectations of future rate cuts from the Federal Reserve.\r\nThe Dow dropped by more than 500 points, or 1.2%… [+3144 chars]" } ] }
- All fields are required
Tests are written using Tap and Supertest. Run the tests with:
npm run test