A professional RESTful Blog API built with Spring Boot 3.3.4 and Java 21. This project demonstrates modern backend development practices with clean architecture, comprehensive testing, and production-ready features.
- Complete CRUD Operations for blog posts
- RESTful API Design with proper HTTP status codes
- PostgreSQL Database with JPA/Hibernate
- Comprehensive Error Handling with custom exceptions
- API Documentation with Swagger/OpenAPI 3
- Data Validation using Bean Validation
- Unit & Integration Testing with JUnit 5 and REST Assured
- Docker Support for database setup
- Clean Architecture (Controller β Service β Repository)
- Java 21 - Latest LTS version
- Spring Boot 3.3.4 - Main framework
- Spring Data JPA - Database operations
- PostgreSQL - Production database
- H2 Database - Testing database
- Maven - Dependency management
- Lombok - Reduce boilerplate code
- SpringDoc OpenAPI - API documentation
- Docker - Database containerization
Before running this application, make sure you have:
- Java 21+ installed
- Maven 3.6+ installed
- Docker and Docker Compose installed
- Git installed
If you see "red methods" errors:
- Enable annotation processing in IntelliJ settings
- Invalidate caches and restart
- Run
mvn clean compile
src/
βββ main/
β βββ java/com/blog/blogapi/
β β βββ config/ # Comprehensive API documentation
β β βββ controller/ # REST controllers
β β βββ DTO/ # Data transfer objects
β β βββ exception/ # Custom exceptions & error handling
β β βββ mapper/ # DTO mappers transforming data between different object representations
β β βββ model/ # Entities
β β βββ service/ # Business logic
β β βββ repository/ # Data access layer
β β βββ BlogapiApplication.java
β βββ resources/
β βββ application.properties
βββ test/ # Unit and integration tests
git clone https://github.com/m4n50/springboot-blog-api.git
cd springboot-blog-api# Create and start PostgreSQL container
docker run --name blog-postgres \
-e POSTGRES_DB=blogapi \
-e POSTGRES_USER=bloguser \
-e POSTGRES_PASSWORD=blogpass \
-p 5432:5432 \
-d postgres:15
# Verify container is running
docker psUpdate src/main/resources/application.properties if needed:
spring.datasource.url=jdbc:postgresql://localhost:5432/blogapi
spring.datasource.username=bloguser
spring.datasource.password=blogpass# Build the project
mvn clean compile
# Run tests
mvn test
# Start the application
mvn spring-boot:runThe application will start on http://localhost:8080
Once the application is running, you can access:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/posts |
Get all blog posts |
| GET | /api/posts/{id} |
Get a specific post |
| POST | /api/posts |
Create a new post |
| PUT | /api/posts/{id} |
Update an existing post |
| DELETE | /api/posts/{id} |
Delete a post |
Create a Post (POST /api/posts)
{
"title": "Getting Started with Spring Boot",
"content": "Spring Boot makes it easy to create stand-alone, production-grade applications...",
"author": "John Doe"
}Response
{
"id": 1,
"title": "Getting Started with Spring Boot",
"content": "Spring Boot makes it easy to create stand-alone, production-grade applications...",
"author": "John Doe",
"createdAt": "2024-09-09T10:30:00",
"updatedAt": "2024-09-09T10:30:00"
}Run the test suite:
# Run all tests
mvn test
# Run only unit tests
mvn test -Dtest="*Test"
# Run only integration tests
mvn test -Dtest="*IT"
# Generate test coverage report
mvn jacoco:reportdocker run --name blog-postgres \
-e POSTGRES_DB=blogapi \
-e POSTGRES_USER=bloguser \
-e POSTGRES_PASSWORD=blogpass \
-p 5432:5432 \
-d postgres:15# Build application image
docker build -t blog-api .
# Run with Docker Compose
docker-compose up -d- Separation of Concerns: Controllers handle HTTP, Services contain business logic, Repositories manage data
- Dependency Injection: Proper use of Spring's IoC container
- Single Responsibility: Each class has a focused purpose
- Global Exception Handler: Centralized error handling
- Custom Exceptions: Domain-specific error types
- Proper HTTP Status Codes: RESTful error responses
- Bean Validation: Input validation using annotations
- Custom Validators: Business rule validation
- Error Messages: User-friendly validation feedback
- Unit Tests: Test individual components in isolation
- Integration Tests: Test component interactions
- REST Assured: API endpoint testing
- User Authentication & Authorization (JWT)
- User Roles (Admin, Author, Reader)
- Post Categories & Tags
- Pagination & Sorting
- Search Functionality
- File Upload for Images
- Caching with Redis
- API Versioning
- CI/CD Pipeline
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Bruno Manso - Backend Developer
- GitHub: @m4n50
- LinkedIn: https://www.linkedin.com/in/bruno-manso-17120542/
- Email: bmansoweb@gmail.com
- Spring Boot team for the excellent framework
- PostgreSQL community for the robust database
- Docker for simplifying development environments
β Star this repository if it helped you learn Spring Boot!