The simplest possible Spring Boot REST API. Three layers, one file each, ~4 Java files total. Use this as your starting point —
lab06_students_api/is the production-grade version you can graduate to later.
src/main/java/tz/ac/suza/wt/studentsapi/
├── StudentsApiApplication.java # main()
├── entity/Student.java # the table
├── repository/StudentRepository.java # CRUD comes free
└── controller/StudentController.java # the 5 endpoints
No DTOs. No service layer. No @RestControllerAdvice. No Docker. No tests. No Swagger.
Just enough to see CRUD work end to end.
apt install postgresql on Linux).psql -d postgres -c "CREATE USER studentsapi WITH PASSWORD 'studentsapi';"
psql -d postgres -c "CREATE DATABASE studentsdb OWNER studentsapi;"
mvn spring-boot:run
The app boots on http://localhost:8080. Hibernate creates the students table on first run.
curl -s http://localhost:8080/api/students
Empty array on first run — that’s correct.
curl -s -X POST http://localhost:8080/api/students \
-H 'Content-Type: application/json' \
-d '{"name":"Asha","email":"asha@example.com","course":"BCS","year":2}'
You get back the created student with an id. Now GET /api/students returns one item.
Open requests.http in VS Code (REST Client extension) for the full set.
| Method | URL | What it does |
|---|---|---|
GET |
/api/students |
List all |
GET |
/api/students/{id} |
Get one |
POST |
/api/students |
Create |
PUT |
/api/students/{id} |
Update |
DELETE |
/api/students/{id} |
Delete |
When this version makes sense, study ../lab06_students_api/ and the
full walkthrough — same API, but with DTOs, a service layer,
global error handling, Docker, and Swagger. Same problem, production-grade.