Build a REST API with Spring Boot

Spring Boot: REST API is an advanced-level course of 5 lessons (about 2 h 40 min), with 15 exercises and 15 quiz questions. Prerequisites: Collections, Streams, and Exceptions, HTTP and REST APIs. The course needs a full project environment, planned for a later phase of the platform.

  • Java
  • Advanced
  • 5 lessons
  • 2 h 40 min
  • 15 exercises
  • Full project environment (phase 2)

The course in brief

This course guides you through building a complete REST API with Spring Boot 4.1 and Java 25. You will expose resources with the right HTTP verbs and status codes, validate incoming data with DTOs, organize your code in layers using dependency injection, then centralize error handling in the ProblemDetail format and test your controllers with MockMvc. The runnable exercises test the logic in plain Java, while the hands-on tasks are carried out in your development environment.

What you will be able to do

  • Create and run a Spring Boot project and expose REST endpoints that return JSON
  • Design a CRUD that respects HTTP semantics (verbs, status codes 200, 201, 204, 400, 404, 409)
  • Define DTOs with records and validate inputs with Jakarta Bean Validation
  • Structure the application in controller, service, and repository layers with constructor injection
  • Centralize error handling with @RestControllerAdvice and ProblemDetail
  • Test the web layer with @WebMvcTest, MockMvc, and mocks

Syllabus: 5 lessons

    • Generate a Spring Boot project with Spring Initializr and understand its structure
    • Write a REST controller that returns JSON
    • Start the application and call the endpoint with curl

    Spring Boot@RestControllerJSON serialization with Jackson

  1. 02

    Routes, HTTP Verbs, and ResponseEntity

    20 min
    • Expose a complete CRUD with @GetMapping, @PostMapping, @PutMapping, and @DeleteMapping
    • Read path parameters, query parameters, and the JSON body
    • Return the right HTTP status with ResponseEntity (200, 201, 204, 404)

    Request mappings@PathVariable, @RequestParam, @RequestBodyResponseEntity and HTTP status codes

  2. 03

    DTOs and Data Validation

    20 min
    • Separate the objects exposed by the API (DTOs) from internal objects
    • Validate incoming data with Bean Validation (@NotBlank, @Size, @Email, @Positive)
    • Write the mapping between entity and DTO

    DTO (Data Transfer Object)Bean Validation (Jakarta Validation)Entity / DTO mapping

  3. 04

    Service Layer and Dependency Injection

    20 min
    • Organize an API in controller, service, and repository layers
    • Use Spring's constructor dependency injection
    • Implement business rules in a testable service, with an in-memory repository

    Layered architectureSpring container and beansConstructor injection

  4. 05

    Global Error Handling and API Testing

    22 min
    • Centralize the translation of exceptions into HTTP responses with @RestControllerAdvice
    • Return errors in the standard ProblemDetail format (RFC 9457)
    • Test a controller with @WebMvcTest and MockMvc

    @RestControllerAdvice et @ExceptionHandlerProblemDetailMockMvc tests

Final project

Library Management REST API

Using Spring Boot, develop an API for managing books and loans: CRUD for books (title, author, ISBN, number of copies), borrowing and returning a copy, and a paginated list filtered by author. The business rules (no loan without an available copy, unique ISBN) live in a service, the data in an in-memory repository behind an interface, and errors use the ProblemDetail format.

Deliverables

  • The complete Maven project (controllers, validated DTOs, services, repository, error handler)
  • A collection of curl requests or an .http file covering every endpoint and every error case
  • At least 6 @WebMvcTest tests and 4 unit tests of the service
  • A short README describing the endpoints, the return codes, and the run command

Assessment criteria

  • HTTP verbs and status codes are correct (201 + Location, 204, 400, 404, 409)
  • No internal entity is exposed: DTOs for input and output, validation enabled
  • Business rules are in the service, with no dependency on HTTP, using constructor injection
  • Errors are centralized and disclose no internal detail
  • Tests pass with ./mvnw test and cover both nominal and error cases

Frequently asked questions

What are the prerequisites for this Spring Boot course?

You should be comfortable with Java (collections, streams, exceptions) and know the basics of HTTP and REST APIs: verbs, status codes, and JSON.

Which Spring Boot version does this course use?

The course targets Spring Boot 4.1 with Java 25 (LTS), as Spring Initializr generates projects today. The Spring Boot 4 changes that affect the course's concepts are pointed out: the spring-boot-starter-webmvc starter, per-module test starters, Jackson 3, new test imports.

Do I need to install anything?

The code exercises run directly on the platform in plain Java. The hands-on tasks are done in your development environment with a JDK 25, the Maven Wrapper provided by the project, and curl.

Does the course cover the database?

This course uses an in-memory repository to focus on the API. Persistence with JPA and Hibernate is the subject of the next course in the track, which replaces this repository without changing the service.

This course, told for your job

Say what you want to be able to do: “Spring Boot: REST API” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.