================================================================ LAB 6 — Spring Boot REST API: Students CRUD ================================================================ Course: Web Technologies Topic: Lecture 8a (Spring Boot) Time: 3 hours lab + 4 hours self-study ---------------------------------------------------------------- LEARNING GOALS ---------------------------------------------------------------- - Generate a Spring Boot project - Build entity / repository / service / controller layers - Implement a complete CRUD REST API - Validate input with javax/jakarta validation annotations - Test endpoints with curl and a REST client (Postman / Insomnia / VS Code REST Client) ---------------------------------------------------------------- PREREQUISITES ---------------------------------------------------------------- - JDK 21+ - Maven (bundled mvnw works fine) ---------------------------------------------------------------- TASKS ---------------------------------------------------------------- TASK 1 — Generate - Use start.spring.io with: web, data-jpa, h2, validation, lombok - Group: tz.ac.suza.wt - Artifact: students-api TASK 2 — Entity + Repository - Student: id, name, email (unique), course, year (1..4), createdAt - JPA annotations + validation: @NotBlank, @Email, @Min/@Max - StudentRepository extends JpaRepository - Custom finder: findByCourse(String course) TASK 3 — Service + Controller - StudentService: business operations + 404 throwing - StudentController under /api/students with full CRUD - Use proper status codes: 201 Created, 204 No Content - @Valid on create/update bodies TASK 4 — Error handling - @RestControllerAdvice that returns clean JSON errors - Validation errors -> 400 with field messages - Not found -> 404 with message TASK 5 — Test with REST client Save a requests.http file with: POST /api/students (create) GET /api/students (list) GET /api/students/1 PUT /api/students/1 (update) DELETE /api/students/1 Plus one negative test (invalid email). TASK 6 — Document - Add springdoc-openapi-starter-webmvc-ui dependency - Confirm Swagger UI is at /swagger-ui.html ---------------------------------------------------------------- DELIVERABLES ---------------------------------------------------------------- - GitHub repo - requests.http demonstrating CRUD - Screenshot of Swagger UI in README ---------------------------------------------------------------- GRADING (10 marks) ---------------------------------------------------------------- Entity + repository ............... 1 Controller + service .............. 3 Validation + error handling ....... 2 Correct status codes .............. 1 Tested via requests.http .......... 2 Swagger UI live ................... 1