NewsAPI is a RESTful API built with Java and Spring Boot that performs web scraping on the website Sucesso no Campo to collect and store news articles in a MySQL database. It also provides a simple front-end to view and search for articles.
- ✅ Web scraping using Jsoup
- ✅ RESTful API with Spring Boot
- ✅ Search news by title (case-insensitive)
- ✅ Save news with title, content, image, publication date, and source
- ✅ Prevent duplicate news entries
- ✅ Simple HTML front-end to search and view news
Technology | Description |
---|---|
Java 17 | Programming language |
Spring Boot | Backend framework |
Spring Data JPA | ORM and database abstraction |
MySQL | Relational database |
Jsoup | Web scraping library |
HTML + JS | Simple frontend interface |
NewsAPI/
├── src/
│ └── main/
│ ├── java/
│ │ └── com.github.luizstsantos.NewsAPI/
│ │ ├── controller/
│ │ │ ├── ControlNews.java
│ │ │ └── ControlScraper.java
│ │ ├── model/
│ │ │ └── News.java
│ │ ├── repository/
│ │ │ └── NewsRepository.java
│ │ ├── scraper/
│ │ │ └── Scraper.java
│ │ ├── service/
│ │ │ └── NewsService.java
│ │ ├── NewsApiApplication.java
│ │ └── ScraperRunner.java
│ ├── resources/
│ │ ├── static/
│ │ │ ├── index.html
│ │ │ └── news.html
│ │ ├── templates/
│ │ └── application.properties
└── test/
- Java 17+
- Maven
- MySQL Server
Create the database:
CREATE DATABASE NewsAPI CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Update your application.properties
:
spring.datasource.url=jdbc:mysql://localhost:3306/NewsAPI?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
./mvnw spring-boot:run
Or build and run the jar:
mvn clean install
java -jar target/NewsAPI-0.0.1-SNAPSHOT.jar
Method | Endpoint | Description |
---|---|---|
GET | /news |
Returns all news articles |
GET | /news/search |
Search news by title (query param title ) |
Example:
curl http://localhost:8080/news/search?title=agriculture
Open index.html
in your browser, or place it inside src/main/resources/static/
to serve it with Spring Boot.
http://localhost:8080/index.html
Made with 💻 by LuizStSantos
If you like it, give it a ⭐ on GitHub!
This project is licensed under the MIT License.