Spring Boot books REST API for learning, in-memory, Docker & Kubernetes ready
281
A simple Spring Boot REST API designed for Docker and Kubernetes labs.
This project provides a complete in-memory Book Management API with sample data loaded at startup.
The main goal is to let students:
This project is intentionally simple and focuses on:
There is no external database.
All book data is stored in memory, so every restart resets the dataset.
book-manager-api/
|-- pom.xml
|-- Dockerfile
|-- .dockerignore
|-- k8s/
| |-- deployment.yaml
| `-- service.yaml
`-- src/
`-- main/
|-- java/
| `-- dev/archety/bookmanager/
| |-- Img02BmsApplication.java
| |-- config/
| | `-- DataSeeder.java
| |-- controller/
| | |-- BookController.java
| | `-- HomeController.java
| |-- dto/
| |-- exception/
| |-- model/
| |-- repository/
| `-- service/
`-- resources/
`-- application.properties
Educational content, labs, and developer-focused videos by Giovanni Pace:
https://www.youtube.com/@archetydev
When running locally:
http://localhost:8081
Base API path:
/api/books
Endpoint
GET /api/books
Description
Returns the full list of books currently stored in memory.
Example request
curl http://localhost:8081/api/books
Example response
[
{
"id": 1,
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "978-0261103344",
"genre": "Fantasy",
"pages": 310,
"status": "AVAILABLE",
"createdAt": "2026-04-13T14:00:00"
},
{
"id": 2,
"title": "Dune",
"author": "Frank Herbert",
"isbn": "978-0441172719",
"genre": "Science Fiction",
"pages": 688,
"status": "BORROWED",
"createdAt": "2026-04-13T14:00:00"
}
]
Endpoint
GET /api/books/{id}
Description
Returns a single book by ID.
Example request
curl http://localhost:8081/api/books/1
Example response
{
"id": 1,
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "978-0261103344",
"genre": "Fantasy",
"pages": 310,
"status": "AVAILABLE",
"createdAt": "2026-04-13T14:00:00"
}
Example not found response
{
"timestamp": "2026-04-13T14:15:00",
"status": 404,
"error": "Not Found",
"message": "Book with id 99 not found"
}
Endpoint
POST /api/books
Description
Creates a new book in memory.
Example request body
{
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Programming",
"pages": 448,
"status": "AVAILABLE"
}
Example request
curl -X POST http://localhost:8081/api/books \
-H "Content-Type: application/json" \
-d '{
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Programming",
"pages": 448,
"status": "AVAILABLE"
}'
Example response
{
"id": 11,
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Programming",
"pages": 448,
"status": "AVAILABLE",
"createdAt": "2026-04-13T14:20:00"
}
Endpoint
PUT /api/books/{id}
Description
Replaces the full book resource.
Example request body
{
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Software Engineering",
"pages": 455,
"status": "RESERVED"
}
Example request
curl -X PUT http://localhost:8081/api/books/11 \
-H "Content-Type: application/json" \
-d '{
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Software Engineering",
"pages": 455,
"status": "RESERVED"
}'
Example response
{
"id": 11,
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Software Engineering",
"pages": 455,
"status": "RESERVED",
"createdAt": "2026-04-13T14:20:00"
}
Endpoint
PATCH /api/books/{id}/status
Description
Updates only the status field of a book.
Example request body
{
"status": "BORROWED"
}
Example request
curl -X PATCH http://localhost:8081/api/books/11/status \
-H "Content-Type: application/json" \
-d '{
"status": "BORROWED"
}'
Example response
{
"id": 11,
"title": "Refactoring",
"author": "Martin Fowler",
"isbn": "978-0134757599",
"genre": "Software Engineering",
"pages": 455,
"status": "BORROWED",
"createdAt": "2026-04-13T14:20:00"
}
Endpoint
DELETE /api/books/{id}
Description
Deletes a book by ID.
Example request
curl -X DELETE http://localhost:8081/api/books/11
Example response
{
"message": "Book with id 11 deleted successfully"
}
Endpoint
GET /api/books/search
Description
Searches books by optional query parameters:
genrestatusYou can use one of them or both together.
Example request
curl "http://localhost:8081/api/books/search?genre=Fantasy"
Example response
[
{
"id": 1,
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "978-0261103344",
"genre": "Fantasy",
"pages": 310,
"status": "AVAILABLE",
"createdAt": "2026-04-13T14:00:00"
}
]
Example request
curl "http://localhost:8081/api/books/search?status=AVAILABLE"
Example response
[
{
"id": 1,
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"isbn": "978-0261103344",
"genre": "Fantasy",
"pages": 310,
"status": "AVAILABLE",
"createdAt": "2026-04-13T14:00:00"
}
]
Example request
curl "http://localhost:8081/api/books/search?genre=Programming&status=BORROWED"
Example response
[
{
"id": 6,
"title": "The Pragmatic Programmer",
"author": "Andrew Hunt",
"isbn": "978-0135957059",
"genre": "Programming",
"pages": 352,
"status": "BORROWED",
"createdAt": "2026-04-13T14:00:00"
}
]
Endpoint
GET /api/books/count
Description
Returns the total number of books currently in memory.
Example request
curl http://localhost:8081/api/books/count
Example response
{
"count": 10
}
Endpoint
GET /api/books/seed-info
Description
Returns information about the preloaded sample dataset.
Example request
curl http://localhost:8081/api/books/seed-info
Example response
{
"message": "Sample book data loaded in memory",
"count": 10
}
Endpoint
GET /api/books/ping
Description
Simple test endpoint to verify that the API is running.
Example request
curl http://localhost:8081/api/books/ping
Example response
{
"message": "Book Manager API is running"
}
Endpoint
GET /api/books/version
Description
Returns application metadata useful for Kubernetes rollout checks.
Example request
curl http://localhost:8081/api/books/version
Example response
{
"app": "book-manager-api",
"version": "1.0.0",
"profile": "k8s-lab"
}
Endpoint
GET /actuator/health
Description
Used by Kubernetes for readiness and liveness probes.
Example request
curl http://localhost:8081/actuator/health
Example response
{
"status": "UP"
}
Endpoint
GET /actuator/info
Description
Returns application metadata.
Example request
curl http://localhost:8081/actuator/info
Example response
{
"app": {
"name": "book-manager-api",
"version": "1.0.0",
"profile": "k8s-lab"
}
}
The API validates incoming request bodies.
title: requiredauthor: requiredisbn: required and must contain only digits and hyphensgenre: requiredpages: required, min 10, max 5000status: requiredExample validation error
{
"timestamp": "2026-04-13T14:30:00",
"status": 400,
"error": "Bad Request",
"validationErrors": {
"title": "Title is required",
"isbn": "ISBN must contain only digits and hyphens"
}
}
Allowed values for status:
AVAILABLEBORROWEDRESERVEDThe application automatically loads sample books when it starts.
Example records include:
Since everything is stored in memory, restarting the application restores the original dataset.
mvn spring-boot:run
or build and run the jar:
mvn clean package
java -jar target/book-manager-api.jar
docker build -t YOUR_DOCKERHUB_USERNAME/book-manager-api:1.0.0 .
docker run -p 8081:8081 YOUR_DOCKERHUB_USERNAME/book-manager-api:1.0.0
curl http://localhost:8081/api/books
curl http://localhost:8081/actuator/health
docker push YOUR_DOCKERHUB_USERNAME/book-manager-api:1.0.0
Optional latest tag:
docker tag YOUR_DOCKERHUB_USERNAME/book-manager-api:1.0.0 YOUR_DOCKERHUB_USERNAME/book-manager-api:latest
docker push YOUR_DOCKERHUB_USERNAME/book-manager-api:latest
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl get pods
kubectl get deployments
kubectl get svc
kubectl describe deployment book-manager-api
kubectl logs -l app=book-manager-api
The deployment uses:
/actuator/health/actuator/healthThis makes the application suitable for basic Kubernetes health checking demonstrations.
Students can use this project to practice:
/api/books/versionA good exercise flow could be:
/api/books/versionYou can use, modify, share, and distribute this project freely.
If this project helps you, and we ever meet in person, you can buy me a coffee.
Author: Giovanni Pace
YouTube: https://www.youtube.com/@archetydev
This project is intended for educational purposes.
MIT License
Copyright (c) 2026 Giovanni Pace
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If this project helped you build something useful or learn something new, consider offering a coffee ☕
The best way to support my work is by subscribing to my YouTube channel: https://youtube.com/@archety
Content type
Image
Digest
sha256:652d8e3c0…
Size
109.8 MB
Last updated
6 months ago
docker pull archety/books-api-in-memory