Plain RESTful Web Service with Spring Boot 4. Using PostgreSQL database, Hibernate and basic authentication. Also added the lombok.
- stars
- 68
- watchers
- 2
- forks
- 62
- open issues
- 0
- Last updated
- 02/06/2026
Plain RESTful Web Service with Spring Boot 4. Using PostgreSQL database, Hibernate and basic authentication. Also added the lombok.
Educational project: REST API for managing books built with Spring Boot 4 and PostgreSQL.
Before starting, make sure you have installed:
java -versionmvn -versiondocker --versiongit clone https://github.com/OKaluzny/spring-boot-rest-api-postgresql.git
cd spring-boot-rest-api-postgresqldocker-compose up -d postgres
Verify the container is running:
docker ps
You should see container book-db with status Up.
mvn spring-boot:run
Wait for the message:
Started Application in X seconds
Open in browser: http://localhost:8080/swagger-ui.html
Here you can interactively test the API.
API requires authentication:
useruserIn Swagger UI click the "Authorize" button and enter these credentials.
Create a book:
curl -X POST http://localhost:8080/api/books \ -H "Content-Type: application/json" \ -u user:user \ -d '{"name": "Java Programming", "description": "Learn Java", "tags": ["java"]}'
Response:
{
"id": 1,
"name": "Java Programming",
"description": "Learn Java",
"tags": ["java"]
}Get all books:
curl http://localhost:8080/api/books -u user:user
| Method | URL | Description |
|---|---|---|
POST |
/api/books |
Create a book |
GET |
/api/books |
Get all books (paginated) |
GET |
/api/books/{id} |
Get book by ID |
GET |
/api/books?name=Java |
Search by name |
PUT |
/api/books/{id} |
Update a book |
DELETE |
/api/books/{id} |
Delete a book |
GET /api/books?page=0&size=10&sort=name,asc
page — page number (starting from 0)size — number of items per pagesort — sorting (field,direction)src/main/java/com/kaluzny/
│
├── Application.java # Entry point
│
├── config/ # Configuration
│ ├── SecurityConfig.java # Security settings
│ └── OpenApiConfig.java # Swagger settings
│
├── domain/ # Data layer
│ ├── Book.java # JPA entity
│ └── BookRepository.java # Repository
│
├── dto/ # Data Transfer Objects
│ ├── BookCreateRequest.java
│ ├── BookUpdateRequest.java
│ ├── BookResponse.java
│ └── BookMapper.java
│
├── service/ # Business logic
│ └── BookService.java
│
├── exception/ # Error handling
│ ├── BookNotFoundException.java
│ └── GlobalExceptionHandler.java
│
└── web/ # REST controllers
└── BookRestController.java
HTTP Request
↓
┌─────────────────┐
│ Controller │ ← Receives DTO, validation
└────────┬────────┘
↓
┌─────────────────┐
│ Service │ ← Business logic
└────────┬────────┘
↓
┌─────────────────┐
│ Repository │ ← Database operations
└────────┬────────┘
↓
┌─────────────────┐
│ PostgreSQL │
└─────────────────┘
Ctrl+C in terminaldocker-compose down
mvn testTests use H2 in-memory database, PostgreSQL is not required.
| URL | Description |
|---|---|
| http://localhost:8080/swagger-ui.html | Swagger UI |
| http://localhost:8080/v3/api-docs | OpenAPI JSON |
| http://localhost:8080/actuator/health | Health check |
Find and stop the process:
lsof -i :8080 kill -9 <PID>
Check that container is running:
docker ps docker-compose up -d postgres
Install Docker Desktop: https://www.docker.com/products/docker-desktop
| Technology | Version | Description |
|---|---|---|
| Java | 17 | Programming language |
| Spring Boot | 4.0.2 | Framework |
| Spring Data JPA | - | ORM for database |
| Spring Security | - | Security |
| PostgreSQL | 16 | Database |
| Swagger/OpenAPI | 3.1 | API documentation |
| Lombok | 1.18 | Reduce boilerplate |
| JUnit 5 | - | Testing |
MIT