Spring Boot teams and players (OTM) REST API for learning, in-memory, Docker & Kubernetes ready
313
A simple Spring Boot REST API designed for Docker and Kubernetes labs.
This project provides a complete in-memory Team 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 team and player data is stored in memory, so every restart resets the dataset.
team-manager-api/
|-- pom.xml
|-- Dockerfile
|-- .dockerignore
|-- k8s/
| |-- deployment.yaml
| `-- service.yaml
`-- src/
`-- main/
|-- java/
| `-- dev/archety/teammanager/
| |-- Img03TmsApplication.java
| |-- config/
| | `-- DataSeeder.java
| |-- controller/
| | |-- TeamController.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:8082
Base API path:
/api/teams
This project demonstrates a simple One To Many relationship:
TeamPlayerEach team contains a list of players, and player operations are exposed through nested endpoints.
Endpoint
GET /api/teams
Description
Returns the full list of teams currently stored in memory, including their players.
Example request
curl http://localhost:8082/api/teams
Example response
[
{
"id": 1,
"name": "Falcons",
"city": "Rome",
"league": "Serie A",
"status": "ACTIVE",
"createdAt": "2026-04-13T14:00:00",
"players": [
{
"id": 1,
"firstName": "Marco",
"lastName": "Rossi",
"position": "Goalkeeper",
"jerseyNumber": 1,
"status": "AVAILABLE"
}
]
}
]
Endpoint
GET /api/teams/{id}
Description
Returns a single team by ID with all its players.
Example request
curl http://localhost:8082/api/teams/1
Example response
{
"id": 1,
"name": "Falcons",
"city": "Rome",
"league": "Serie A",
"status": "ACTIVE",
"createdAt": "2026-04-13T14:00:00",
"players": [
{
"id": 1,
"firstName": "Marco",
"lastName": "Rossi",
"position": "Goalkeeper",
"jerseyNumber": 1,
"status": "AVAILABLE"
},
{
"id": 2,
"firstName": "Luca",
"lastName": "Bianchi",
"position": "Defender",
"jerseyNumber": 5,
"status": "AVAILABLE"
}
]
}
Example not found response
{
"timestamp": "2026-04-13T14:15:00",
"status": 404,
"error": "Not Found",
"message": "Team with id 99 not found"
}
Endpoint
POST /api/teams
Description
Creates a new team in memory.
Example request body
{
"name": "Wolves",
"city": "Naples",
"league": "Serie B",
"status": "ACTIVE"
}
Example request
curl -X POST http://localhost:8082/api/teams \
-H "Content-Type: application/json" \
-d '{
"name": "Wolves",
"city": "Naples",
"league": "Serie B",
"status": "ACTIVE"
}'
Example response
{
"id": 4,
"name": "Wolves",
"city": "Naples",
"league": "Serie B",
"status": "ACTIVE",
"createdAt": "2026-04-13T14:20:00",
"players": []
}
Endpoint
PUT /api/teams/{id}
Description
Replaces the full team resource.
Example request body
{
"name": "Wolves",
"city": "Naples",
"league": "Premier League",
"status": "REBUILDING"
}
Example request
curl -X PUT http://localhost:8082/api/teams/4 \
-H "Content-Type: application/json" \
-d '{
"name": "Wolves",
"city": "Naples",
"league": "Premier League",
"status": "REBUILDING"
}'
Endpoint
PATCH /api/teams/{id}/status
Description
Updates only the status field of a team.
Example request body
{
"status": "CHAMPION"
}
Example request
curl -X PATCH http://localhost:8082/api/teams/4/status \
-H "Content-Type: application/json" \
-d '{
"status": "CHAMPION"
}'
Endpoint
POST /api/teams/{teamId}/players
Description
Adds a child resource to the selected team. This is the main endpoint that demonstrates the One To Many relationship.
Example request body
{
"firstName": "Paolo",
"lastName": "Neri",
"position": "Midfielder",
"jerseyNumber": 6,
"status": "AVAILABLE"
}
Example request
curl -X POST http://localhost:8082/api/teams/4/players \
-H "Content-Type: application/json" \
-d '{
"firstName": "Paolo",
"lastName": "Neri",
"position": "Midfielder",
"jerseyNumber": 6,
"status": "AVAILABLE"
}'
Example response
{
"id": 4,
"name": "Wolves",
"city": "Naples",
"league": "Premier League",
"status": "REBUILDING",
"createdAt": "2026-04-13T14:20:00",
"players": [
{
"id": 9,
"firstName": "Paolo",
"lastName": "Neri",
"position": "Midfielder",
"jerseyNumber": 6,
"status": "AVAILABLE"
}
]
}
Endpoint
PATCH /api/teams/{teamId}/players/{playerId}/status
Description
Updates the status of one player belonging to a specific team.
Example request body
{
"status": "INJURED"
}
Example request
curl -X PATCH http://localhost:8082/api/teams/4/players/9/status \
-H "Content-Type: application/json" \
-d '{
"status": "INJURED"
}'
Endpoint
DELETE /api/teams/{teamId}/players/{playerId}
Description
Removes a player from the selected team.
Example request
curl -X DELETE http://localhost:8082/api/teams/4/players/9
Endpoint
DELETE /api/teams/{id}
Description
Deletes a team by ID.
Example request
curl -X DELETE http://localhost:8082/api/teams/4
Example response
{
"message": "Team with id 4 deleted successfully"
}
Endpoint
GET /api/teams/search
Description
Searches teams by optional query parameters:
leaguestatusYou can use one of them or both together.
Example request
curl "http://localhost:8082/api/teams/search?league=Serie%20A"
Example request
curl "http://localhost:8082/api/teams/search?status=ACTIVE"
Example request
curl "http://localhost:8082/api/teams/search?league=Premier%20League&status=CHAMPION"
Endpoint
GET /api/teams/count
Description
Returns the total number of teams currently in memory.
Example request
curl http://localhost:8082/api/teams/count
Example response
{
"count": 3
}
Endpoint
GET /api/teams/seed-info
Description
Returns information about the preloaded sample dataset.
Example request
curl http://localhost:8082/api/teams/seed-info
Example response
{
"message": "Sample team data loaded in memory",
"count": 3
}
Endpoint
GET /api/teams/ping
Description
Simple test endpoint to verify that the API is running.
Example request
curl http://localhost:8082/api/teams/ping
Example response
{
"message": "Team Manager API is running"
}
Endpoint
GET /api/teams/version
Description
Returns application metadata useful for Kubernetes rollout checks.
Example request
curl http://localhost:8082/api/teams/version
Example response
{
"app": "team-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:8082/actuator/health
Example response
{
"status": "UP"
}
Endpoint
GET /actuator/info
Description
Returns application metadata.
Example request
curl http://localhost:8082/actuator/info
Example response
{
"app": {
"name": "team-manager-api",
"version": "1.0.0",
"profile": "k8s-lab"
}
}
The API validates incoming request bodies.
name: requiredcity: requiredleague: requiredstatus: requiredfirstName: requiredlastName: requiredposition: requiredjerseyNumber: required, min 0, max 99status: requiredExample validation error
{
"timestamp": "2026-04-13T14:30:00",
"status": 400,
"error": "Bad Request",
"validationErrors": {
"name": "Name is required",
"jerseyNumber": "Jersey number must be less than or equal to 99"
}
}
Allowed values for team status:
ACTIVEREBUILDINGCHAMPIONAllowed values for player status:
AVAILABLEINJUREDSUSPENDEDThe application automatically loads sample teams and players when it starts.
Example teams include:
Example players 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/team-manager-api.jar
docker build -t YOUR_DOCKERHUB_USERNAME/team-manager-api:1.0.0 .
docker run -p 8082:8082 YOUR_DOCKERHUB_USERNAME/team-manager-api:1.0.0
curl http://localhost:8082/api/teams
curl http://localhost:8082/actuator/health
docker push YOUR_DOCKERHUB_USERNAME/team-manager-api:1.0.0
Optional latest tag:
docker tag YOUR_DOCKERHUB_USERNAME/team-manager-api:1.0.0 YOUR_DOCKERHUB_USERNAME/team-manager-api:latest
docker push YOUR_DOCKERHUB_USERNAME/team-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 team-manager-api
kubectl logs -l app=team-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/teams/versionA good exercise flow could be:
/api/teams/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.
Content type
Image
Digest
sha256:070871b55…
Size
109.8 MB
Last updated
6 months ago
docker pull archety/teams-players-api-in-memory