- Fetch news from http://feeds.nos.nl/nosjournaal?format=xml
- Save them to a PostgreSQL database
- Expose news via GraphQL endpoint
- openjdk 18
- docker
- maven 3.8.5
- git clone <this repository>
- cd news-provider
- mvn clean install
- docker-compose up
The PostgreSql db will start, news-ingest spring boot application will start to fetch & save news in the database and a GraphQL Endpoint will be available at address: http://localhost:8888/v1/news
Now you can simply access the GraphQL endpoint using Postman:
And add the GraphQL query in the body:
{
findAllNews{
title,
description,
publishedDate,
imageUrl
}
}
NOTE: by default, a maximum of 100 articles will be retrieved!
Controling the pagination and size(default is 10):
{
findAllNews(page: 0, size: 5){
title,
publishedDate,
description
}
}
Other examples:
{
findAllNews(page: 1, size: 10){
title,
publishedDate,
description
}
}
{
findAllNews{
title,
publishedDate
}
}
{
countNews
}
Or any other combination of the fields.
One Maven parent project, packing three Maven modules:
-
news-api: Spring Boot application for exposing GraphQL endpoint
-
news-commons: Holding common data between the other two modules
-
news-ingestion: Spring Boot application with Scheduling Tasks for fetching and saving data
- Scheduling task - Polling news feed from: http://feeds.nos.nl/nosjournaal?format=xml - Frequency: 5 minutes - Save and update news in a relational database using Spring Data jpa - PostgreSql database
Doc reference: https://spring.io/guides/gs/scheduling-tasks/
Endpoint: - /v1/news
Doc reference: https://spring.io/projects/spring-graphql#learn