Java · Advanced level

Advanced level · Module 5 of 6 · 24 guided hours

REST APIs with Spring Boot

Build REST services with Spring Boot: controllers, services, data access, validation, error handling and tests.

Learning objectives

  • Create a Spring Boot application with REST controllers
  • Structure the service with dependency injection and a data layer
  • Validate input, handle errors consistently and test the API

Topics

  • Spring Boot starters and auto-configuration
  • @RestController and request mappings
  • dependency injection
  • Spring Data JDBC or JPA basics
  • Bean Validation
  • @ControllerAdvice
  • MockMvc tests

Lessons

  1. Lesson 1 Your First Spring Boot Service

    Create a Spring Boot project, understand auto-configuration and starters, and return JSON from a controller.

    Spring Boot starterauto-configuration@RestController@GetMapping and @PathVariable

  2. Lesson 2 Layers and Dependency Injection

    Structure the service into controller, service and repository layers wired together by Spring's dependency injection.

    @Service and @Repositoryconstructor injectionSpring Data repositorylayered architecture

  3. Lesson 3 Validation and Error Handling

    Validate request bodies, return correct status codes and give clients consistent, helpful error responses.

    @Valid and @NotBlank / @Positive@RequestBodyResponseEntity and status codes@ControllerAdvice

  4. Lesson 4 Testing Spring Boot APIs

    Test services with plain unit tests and controllers with MockMvc, and run integration tests against a test database.

    unit test vs integration test@WebMvcTest and MockMvc@SpringBootTesttest data setup

Practical activity

Build a small events API for a youth centre with endpoints to create, list and cancel events, including validation and tests.

Expected outcomes

  • Working REST services following conventions
  • Consistent error responses and tested endpoints

Assessment

Practical: add two endpoints with validation and tests to a provided Spring Boot project; marked by automated API tests.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.