A modern RESTful API for managing books, built with Spring Boot 4 and MongoDB.
- RESTful API with CRUD operations
- Spring Boot 4.0.2 with Spring Framework 7
- MongoDB with embedded database for development
- Spring Security with Basic Authentication
- Spring Data REST with HAL support
- Bean Validation (Jakarta Validation)
- Lombok for boilerplate reduction
- JUnit 5 tests with embedded MongoDB
| Technology | Version |
|---|---|
| Java | 21 |
| Spring Boot | 4.0.2 |
| Spring Framework | 7.0.3 |
| MongoDB Driver | 5.6.2 |
| Embedded MongoDB | 6.0.9 |
| Apache Tomcat | 11.0.15 |
| JUnit | 5 |
src/
├── main/
│ ├── java/com/kaluzny/
│ │ ├── Application.java # Main entry point
│ │ ├── domain/
│ │ │ ├── Book.java # Entity model
│ │ │ └── BookRepository.java # Data repository
│ │ └── web/
│ │ └── BookController.java # REST controller
│ └── resources/
│ └── application.yml # Configuration
└── test/
└── java/com/kaluzny/
└── AppTest.java # Integration tests
- Java 21 or higher
- Maven 3.8+
mvn spring-boot:runThe application will start on http://localhost:8080
mvn testAll endpoints require Basic Authentication:
- Username:
user - Password:
user
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/books |
Get all books |
GET |
/api/books/{id} |
Get book by ID |
POST |
/api/books |
Create a new book |
DELETE |
/api/books/{id} |
Delete book by ID |
DELETE |
/api/books |
Delete all books |
curl -u user:user http://localhost:8080/api/booksResponse:
[
{
"id": 1,
"name": "Java SE",
"description": "Programming"
},
{
"id": 2,
"name": "Java EE",
"description": "Programming"
}
]curl -u user:user http://localhost:8080/api/books/1Response:
{
"id": 1,
"name": "Java SE",
"description": "Programming"
}curl -u user:user -X POST http://localhost:8080/api/books \
-H "Content-Type: application/json" \
-d '{"id": 3, "name": "Spring in Action", "description": "Framework"}'curl -u user:user -X DELETE http://localhost:8080/api/books/3| Field | Type | Constraints |
|---|---|---|
id |
Integer | Primary Key |
name |
String | Required, min length 1 |
description |
String | Required, min length 1 |
spring:
data:
mongodb:
database: Books
security:
user:
name: user
password: user
server:
port: 8080| Variable | Description | Default |
|---|---|---|
SERVER_PORT |
Application port | 8080 |
SPRING_DATA_MONGODB_URI |
MongoDB connection URI | embedded |
SPRING_SECURITY_USER_NAME |
Auth username | user |
SPRING_SECURITY_USER_PASSWORD |
Auth password | user |
mvn clean package -DskipTestsjava -jar target/Simple\ RESTful\ Web\ Service\ with\ Spring\ Boot\ and\ MongoDB.jarFROM eclipse-temurin:21-jre
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]docker build -t spring-boot-mongodb .
docker run -p 8080:8080 spring-boot-mongodbThis project uses GitHub Actions for continuous integration.
| Job | Description |
|---|---|
| Build & Test | Compiles code, runs tests, packages JAR |
| Code Quality | Generates JaCoCo coverage report |
- Push to
masterormainbranch - Pull requests to
masterormainbranch
Each successful build produces:
app-jar— Application JAR filecoverage-report— JaCoCo test coverage report
This project is licensed under the MIT License.
Oleg Kaluzny
Made with Spring Boot 4