AI Instructor Live Labs Included

Building REST APIs with Spring Boot

Build a production-quality REST API with Spring Boot and PostgreSQL. Covers controllers, service layers, JPA, Bean Validation, error handling, and pagination through incremental hands-on exercises.

Intermediate
18h 30m
14 Lessons
SMU-JAVA-REST
Building REST APIs with Spring Boot Badge

View badge details

About This Course

Build a production-quality Task Manager REST API from scratch using Spring Boot, Spring Data JPA, and PostgreSQL. This course covers Spring Boot fundamentals, REST controllers, service layer design, JPA persistence, Bean Validation, global exception handling, and pagination. Students incrementally build a fully functional API that serves as a portfolio piece.

Course Curriculum

14 Lessons
01
AI Lesson
AI Lesson

Spring Boot Fundamentals & Project Setup

1h 0m

Learn what Spring Boot is and why it exists. Covers auto-configuration, the Spring application context, Maven project structure, @SpringBootApplication, embedded Tomcat, application.properties, Spring Boot starter dependencies, and running and verifying a Spring Boot app.

02
Lab Exercise
Lab Exercise

Spring Boot Setup - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises verifying the Spring Boot starter project, creating a HelloController with REST endpoints, and adding a health check endpoint. Students confirm the Meridian Logistics API starts and responds correctly.

Verify the Spring Boot Application Starts Open the starter project, review pom.xml and Application.java, then run mvn spring-boot:run to confirm the application starts without errors on port 8080. ~15 min
Create HelloController Create a HelloController in com.skillmeup.taskapi.controller annotated with @RestController. Add a GET /api/hello endpoint returning a JSON greeting {"message": "Meridian Logistics API is running"}. ~15 min
Add a Health Check Endpoint Add a GET /api/health endpoint to HelloController returning {"status": "UP", "service": "task-api"}. Verify both /api/hello and /api/health endpoints respond correctly using curl or the browser. ~15 min
03
AI Lesson
AI Lesson

REST Controllers & HTTP Methods

1h 0m

Learn REST conventions, Spring MVC controller annotations (@RestController, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping), path variables, request parameters, request body deserialization, ResponseEntity for status codes, and the importance of DTOs over exposing JPA entities directly.

04
Lab Exercise
Lab Exercise

REST Controllers - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises implementing stub methods in TaskController: returning a hardcoded task list, echoing a POST request body, returning a single task, and testing all endpoints with curl commands.

Implement getAllTasks and Return a Hardcoded List Fill in TaskController.getAllTasks() to return a hardcoded List.of(new TaskResponse(...)) with one sample task. Confirm GET /api/tasks returns 200 OK with a JSON array containing one task object. ~15 min
Implement getTask and createTask Fill in getTask(@PathVariable Long id) to return a hardcoded TaskResponse with 200 OK. Fill in createTask(@RequestBody TaskRequest request) to echo the request fields back in a TaskResponse with a hardcoded id=1L and return 201 Created. ~15 min
Test All Endpoints with curl Test GET /api/tasks, GET /api/tasks/1, and POST /api/tasks using the curl commands provided. Verify GET returns 200 with JSON array, GET by ID returns 200 with a single task, and POST returns 201 Created with the echoed task body including id=1. ~15 min
05
AI Lesson
AI Lesson

Service Layer & Dependency Injection

1h 0m

Learn why the service layer exists, how Spring manages beans (@Service, @Component, @Repository), constructor injection vs field injection, interface-based service design, and the controller-service-repository chain. Emphasizes why constructor injection is preferred over @Autowired field injection.

06
Lab Exercise
Lab Exercise

Service Layer - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises implementing TaskService interface and TaskServiceImpl with an in-memory List backing store, wiring TaskController to use constructor-injected TaskService, and verifying the full controller-service chain with curl POST and GET commands.

Implement getAllTasks and getTask in TaskServiceImpl Add a private List<Task> field to TaskServiceImpl as the in-memory store. Implement getAllTasks() to map all tasks to TaskResponse. Implement getTask(Long id) to find by id, throwing RuntimeException if not found. ~15 min
Implement createTask and Wire TaskController to TaskService Implement createTask(TaskRequest request) in TaskServiceImpl — assign a generated id, construct a Task, add to the list, return TaskResponse. Update TaskController to use constructor-injected TaskService instead of hardcoded responses. Wire getAllTasks and createTask methods. ~15 min
Verify the Full Service Chain with curl Run the app and use curl to POST two tasks, then GET all tasks to verify both appear. Confirm tasks persist within the same JVM run but reset on restart (expected for in-memory store — JPA in Lesson 8 fixes this). Test GET by ID returns the correct task. ~15 min
07
AI Lesson
AI Lesson

Spring Data JPA & Repositories

1h 0m

Learn JPA entity annotations (@Entity, @Table, @Id, @GeneratedValue, @Column, @Enumerated), entity lifecycle, Spring Data JpaRepository with built-in CRUD methods, derived query methods, @Transactional, and ddl-auto settings. Students understand how to configure PostgreSQL persistence for the Task API.

08
Lab Exercise
Lab Exercise

JPA & Repositories - Lab Exercises

1h 30m 3 Exercises

Hands-on exercises annotating Task.java as a JPA entity, creating TaskRepository with derived query methods, switching TaskServiceImpl from in-memory List to repository calls, and verifying that tasks persist across server restarts using PostgreSQL.

Annotate Task.java as a JPA Entity Open Task.java (plain Java class). Add @Entity, @Table(name="tasks"), @Id, @GeneratedValue(strategy=IDENTITY), and @Column annotations. Add @Enumerated(EnumType.STRING) to the status field with TaskStatus enum. Add @PrePersist lifecycle callback to set createdAt. ~15 min
Create TaskRepository and Add Derived Query Methods Open TaskRepository.java (stub extends JpaRepository<Task, Long>). Add findByStatus(TaskStatus status) and findByDueDateBefore(LocalDate date) derived query methods. Confirm Spring Data generates the queries automatically without SQL. ~15 min
Switch TaskServiceImpl to Use Repository and Verify Persistence Open TaskServiceImpl. Replace the in-memory List<Task> with TaskRepository injection. Update getAllTasks, getTask, createTask, updateTask, and deleteTask to use repository methods. Run the app and confirm tasks persist across server restarts — create a task, stop, restart, GET all tasks and verify it still exists. ~15 min
09
AI Lesson
AI Lesson

Request Validation & Error Handling

1h 0m

Learn Bean Validation (@Valid, @NotBlank, @NotNull, @Size, @FutureOrPresent), @RestControllerAdvice for global exception handling, structured ApiError response body, custom TaskNotFoundException, and proper HTTP status codes for validation failures (400) vs missing resources (404).

10
Lab Exercise
Lab Exercise

Validation & Errors - Lab Exercises

1h 50m 4 Exercises

Hands-on practice adding Bean Validation and global error handling to the Task Manager REST API. Annotate DTOs, build a GlobalExceptionHandler, and implement custom exceptions with meaningful error responses.

Add Bean Validation Annotations to Task DTOs Annotate CreateTaskRequest and UpdateTaskRequest with Bean Validation constraints and enable validation on controller endpoints. ~15 min
Build a GlobalExceptionHandler Create a @RestControllerAdvice class that catches MethodArgumentNotValidException and TaskNotFoundException, returning structured ApiError responses. ~20 min
Implement TaskNotFoundException Create TaskNotFoundException as a custom RuntimeException, throw it from TaskService when a task is not found, and verify the handler returns HTTP 404. ~15 min
Test Validation and Error Responses End-to-End Use curl or the REST client to send invalid requests and missing-task requests, verifying the correct HTTP status codes and ApiError JSON structure are returned. ~15 min
11
AI Lesson
AI Lesson

Pagination, Filtering & Sorting

30m

Learn how Spring Data JPA's Pageable abstraction enables efficient large-dataset queries, how to add filtering by status and sorting by dueDate, and how to return Page objects with metadata to API consumers.

12
Lab Exercise
Lab Exercise

Pagination - Lab Exercises

1h 40m 3 Exercises

Hands-on practice adding Pageable support to the Task Manager API, implementing status filtering, enabling dueDate sorting, and verifying the Page response structure.

Add Pageable to the Task Repository and Service Extend TaskRepository with a paginated findByStatus method and update TaskService to return Page<TaskResponse>. ~20 min
Add @PageableDefault to the Controller Update the GET /api/tasks endpoint to accept a Pageable parameter with @PageableDefault defaults and optional status filter. ~15 min
Test Pagination, Filtering, and Sorting Use curl to test paginated requests with status filters and sort parameters, verifying the Page metadata fields in the JSON response. ~20 min
13
AI Lesson
AI Lesson

Capstone Briefing

20m

A comprehensive review of all API development skills covered in the course and a detailed briefing on the Task Manager capstone project requirements including the Category entity that students will implement in the final lesson.

14
Lab Exercise
Lab Exercise

Capstone Project

3h 10m 6 Exercises

The final capstone project for Building REST APIs with Spring Boot. Students implement a complete Category management feature including entity relationships, full CRUD endpoints, validation, error handling, and paginated task listing.

Implement the Category Entity and Repository Complete the Category JPA entity with all required annotations, establish the OneToMany relationship with Task, and implement CategoryRepository. ~25 min
Implement CategoryService with Business Rules Implement all CategoryService methods: create (with duplicate name check), getAll, getById, update, and delete (with assigned-tasks guard). ~30 min
Implement CategoryController Build all six CategoryController endpoints including the paginated GET /api/categories/{id}/tasks endpoint and register CategoryNotFoundException in GlobalExceptionHandler. ~25 min
Assign Tasks to Categories Update TaskService and TaskController to accept an optional categoryId when creating or updating a task, and include the category name in TaskResponse. ~20 min
Add Validation and Error Handling for Categories Add @Valid to category controller endpoints, throw CategoryNotFoundException for missing IDs, and return 409 Conflict for duplicate category names. ~20 min
End-to-End Capstone Verification Test the complete Category + Task API end-to-end: create categories, assign tasks, paginate tasks by category, verify error responses, and confirm business rule enforcement. ~25 min

This course includes:

  • 24/7 AI Instructor Support
  • Live Lab Environments
  • 7 Hands-on Lessons
  • 6 Months Access
  • Completion Badge
  • Certificate of Completion
Building REST APIs with Spring Boot Badge

Earn Your Badge

Complete all lessons to unlock the Building REST APIs with Spring Boot achievement badge.

Category
Skill Level Intermediate
Total Duration 18h 30m
Building REST APIs with Spring Boot Badge
Achievement Badge

Building REST APIs with Spring Boot

Awarded for completing the Spring Boot REST API course, demonstrating proficiency in building, securing, and documenting RESTful APIs with Spring Boot.

Course Building REST APIs with Spring Boot
Criteria Complete all lessons and pass assessments in the Building REST APIs with Spring Boot course.
Valid For 730 days

Skills You'll Earn

Spring Boot REST API Design Spring MVC API Documentation Input Validation Error Handling

Complete all lessons in this course to earn this badge