Java & Springboot (Backend-only) News aggregator project to register new user, authenticate the user by JWT during login and provide token and fetch news using Third-party API for the categories set by User.
POST /api/register
: Register a new user.POST /api/signin
: Authenticate a user and issue a JWT token.
GET /api/preferences
: Retrieve the logged-in user's news preferences.PUT /api/preferences
: Update the logged-in user's news preferences.
GET /api/news
: Fetch personalized news articles from external APIs based on user preferences.
- Spring Boot: Core framework.
- Spring Security: JWT-based authentication.
- Maven: Build tool.
- In-Memory Database (H2 Database): Stores user data and preferences.
- External News APIs: Integrates with services like GNews API.
- Spring Web-Client's RestTemplate : Fetches news articles asynchronously.
-
User Registration:
POST /api/register
Example Payload:{ "username": "example_user", "password": "password123", "email": "[email protected]" }
-
User Login:
POST /api/signin
Example Request:{ "username": "example_user", "password": "password123" }
-
Retrieve Preferences:
GET /api/preferences
Requires Bearer Token in Authorization Header. -
Update Preferences:
PUT /api/preferences
Requires Bearer Token in Authorization Header.
Example Payload:{ "categories" : ["Technology", "Health"] }
-
Fetch News:
GET /api/news
Requires Bearer Token in Authorization Header.
Fetches articles based on the user's preferences.
Third party API by GNews API is used to fetch news articles.
Website : https://gnews.io/docs/v4#introduction
Signing up is required on these platforms to obtain API keys.
URL : https://gnews.io/api/v4/top-headlines?category=business,entertainment&lang=en&apikey={API_KEY}
Parameters:
- category(categories of news articles): can be one of the following -> general, world, nation, business, technology, entertainment, sports, science and health
- lang(language of news articles): can be one of the following -> Arabic [ar], Chinese [zh], Dutch [nl], English [en], French [fr], German [de], Greek [el], Hebrew [he], Hindi [hi], Italian [it], Japanese [ja], Malayalam [ml], Marathi [mr], Norwegian [no], Portuguese [pt], Romanian [ro], Russian [ru], Spanish [es], Swedish [sv], Tamil [ta], Telugu [te], Ukrainian [uk]
- apikey : API Key provided by GNews after signup
-
Pre-requisites:
- Java 17 or later
- IntelliJ or similar IDE
- Maven
-
Clone the GitHub Project locally.
-
Create 2 environment variables in System variables:
i. API_KEY : Api key provided by GNews API after creating account.
ii. SECRET_KEY : Secret key to be used while generating token. -
Run the NewsAggregatorAppApplication.java class to start the Springboot project using embedded Apache Tomcat server.