Skip to content

RuchirDixit/news-aggregator-api-with-spring-boot-RuchirDixit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

News Aggregator API project

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.


Features :

1. User Authentication:

  • POST /api/register : Register a new user.
  • POST /api/signin : Authenticate a user and issue a JWT token.

2. News Preferences:

  • GET /api/preferences : Retrieve the logged-in user's news preferences.
  • PUT /api/preferences : Update the logged-in user's news preferences.

3. News Articles:

  • GET /api/news : Fetch personalized news articles from external APIs based on user preferences.

Technologies Used :

  • 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.

API Endpoints:

  1. User Registration:
    POST /api/register
    Example Payload:

    {
        "username": "example_user",
        "password": "password123",
        "email": "[email protected]"
    }
  2. User Login:
    POST /api/signin
    Example Request:

    {
        "username": "example_user",
        "password": "password123"
    }
  3. Retrieve Preferences:
    GET /api/preferences
    Requires Bearer Token in Authorization Header.

  4. Update Preferences:
    PUT /api/preferences
    Requires Bearer Token in Authorization Header.

    Example Payload:

    {
        "categories" : ["Technology", "Health"]
    }
    
  5. Fetch News:
    GET /api/news
    Requires Bearer Token in Authorization Header.

    Fetches articles based on the user's preferences.


Third-Party API Used:

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

Steps to setup the project:

  1. Pre-requisites:

    • Java 17 or later
    • IntelliJ or similar IDE
    • Maven
  2. Clone the GitHub Project locally.

  3. 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.

  4. Run the NewsAggregatorAppApplication.java class to start the Springboot project using embedded Apache Tomcat server.

About

news-aggregator-api-with-spring-boot-RuchirDixit created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%