Backend Java REST API

Spring Boot Lab – Exercises and Mini REST Projects with Spring Boot

Spring Boot Lab: exercises and REST mini-projects with Java. Full CRUD, JPA, DTO, ResponseEntity, CORS and integrated HTML frontend — two real projects.

Course description

Spring Boot Lab: Build Real REST APIs with Guided Exercises

Spring Boot theory is learned from foundational courses — but true mastery comes through practice. In this lab we build two complete REST mini-projects, tackling every concrete problem encountered in a professional project: JPA relationships, DTOs, validation, CORS, integrated frontend and much more. Two parallel tracks — Video Management System and Food API — that together cover all aspects of a modern REST API with Spring Boot.

What You'll Learn

  • Design and build the database with One-To-Many relationships in Spring Data JPA
  • Configure the Spring Boot project with application.properties and dependencies
  • Create JPA entities with @Entity, @Column, updatable and nullable annotations
  • Use Java Records for immutable Response and Request DTOs
  • Implement custom Repositories with JpaRepository and MySQL connection
  • Build the Service layer with @Transactional and constructor Dependency Injection
  • Map Entity ↔ DTO manually with a clean, testable pattern
  • Build ResponseEntity with correct status codes: 200, 201, 204, 404
  • Handle UUID-based searches with Optional to eliminate null pointers
  • Implement the complete REST CRUD: GET, POST, PUT, DELETE
  • Configure CORS Policies in Spring Boot with Bean configuration
  • Build an HTML + Bootstrap + JavaScript frontend that consumes the API
  • Use the Fetch API for GET, POST, DELETE and PUT from the browser

Two Projects, One Complete Journey

The Video Management System tackles One-To-Many relationships and MVC architecture. The Food API brings everything to a more professional level with DTOs, mappers, custom ResponseEntity and an integrated frontend. Together they cover exactly the patterns used every day in a production Spring Boot project.

Who This Course Is For

Designed for Java developers who know the basics of Spring Boot and want to consolidate them with real projects. This is the practical complement to the theoretical Spring Boot courses — knowledge of Java, Spring MVC and basic REST APIs is assumed.

Lessons list

We kick off the Video Management System lab by building the database with a One-To-Many relationship in Spring Boot. I'll walk you through designing the Playlist and Video entity structure and writing the initial SQL scripts.

Guarda lezione

I'll configure the Video Management System Spring Boot project: from the application.properties file to the database connection. We'll cover dependencies, key settings, and how to prepare the environment for the REST API.

Guarda lezione

Let's build the Video Management System models with JPA: I'll create the Playlist and Video entities and configure the One-To-Many mapping using Hibernate's @OneToMany and @ManyToOne annotations in Spring Boot.

Guarda lezione

We'll go deeper into the JPA One-To-Many mapping between Playlist and Video: I'll configure foreign keys, cascades, and fetch options to build a correct and performant relationship in Spring Boot.

Guarda lezione

I'll introduce Java Records as immutable response DTOs for the Video Management System REST API, explaining why Records are the modern choice for representing responses in Spring Boot.

Guarda lezione

I'll show you how to use Java Records for REST API Requests in the Video Management System: we'll build request objects for creating and updating resources, cleanly separating input from output.

Guarda lezione

Let's build the Repository, Service, and Controller for the Video Management System: I'll implement the three fundamental layers of a Spring Boot REST API step by step with best practices and constructor-based Dependency Injection.

Guarda lezione

We'll implement the findAll method to retrieve all Playlists in the Video Management System and take a detailed look at the role of the @Transactional annotation in Spring Boot.

Guarda lezione

Let's implement the POST endpoint to create a new Playlist in the Video Management System: I'll handle request body binding and build the ResponseEntity with a proper 201 Created status code.

Guarda lezione

We wrap up the Video Management System with the POST endpoint to add a Video to a Playlist: I'll use path parameters, manage the One-To-Many relationship, and close out the first mini-project of the lab.

Guarda lezione

Let's get started with the Food API: I'll show you the project goal, define the food domain, and create the MySQL database that will underpin the entire Spring Boot REST API. This is ground zero for a complete CRUD.

Guarda lezione

We continue configuring the Food API project: I'll add Spring Boot dependencies, connect the app to MySQL, and structure the main packages to keep the code clean and scalable from the very beginning.

Guarda lezione

I'll model Java entities with Hibernate for the Food API using @Entity, @Id, and @Column with updatable and nullable options, then introduce DTOs to cleanly separate the persistence layer from the presentation layer.

Guarda lezione

I'll create the Repository interfaces by extending JpaRepository for the Food API and configure a stable connection to MySQL, leveraging Spring Data JPA for clean, boilerplate-free data access.

Guarda lezione

We'll create the FoodService with constructor-based Dependency Injection and I'll introduce @Transactional to ensure persistence consistency across all Food API operations with Spring Boot.

Guarda lezione

I'll explain what DTOs are and why they're essential in a Spring Boot REST API: they protect the domain, simplify client-server communication, and make the code testable. We'll define them as Java Records.

Guarda lezione

I'll implement constructor-based Dependency Injection without @Autowired and build the Food API Controller, showing you how to map entities to DTOs and structure the data flow correctly in and out of the API.

Guarda lezione

I'll implement manual mapping between Entity and DTO in the Food API Service: you'll see how to convert Food to FoodDTO and back using a clean, testable pattern that scales without relying on external libraries.

Guarda lezione

I'll build the custom ResponseEntity for the Food API, setting the correct HTTP status codes — 200, 201, 404 — based on the outcome of each operation to make the API fully REST-compliant.

Guarda lezione

I'll create the GET endpoint to search for a food item by UUID in the Food API, using Optional in the Service layer to handle missing records gracefully and prevent null pointer exceptions in Spring Boot.

Guarda lezione

We'll build the Food API POST endpoint to save a new food item: the controller receives the DTO via @RequestBody, passes it to the Service for transformation, and persists it to MySQL returning a 201 Created response.

Guarda lezione

Let's build the DELETE endpoint for the Food API to remove a food item: I'll return 204 No Content on success and 404 Not Found when the UUID doesn't exist, following REST conventions correctly.

Guarda lezione

I'll implement HTTP PUT updates in the Food API: receiving the UUID as a path variable and the DTO in @RequestBody, then updating data following the DTO → Entity → MySQL persistence pattern.

Guarda lezione

Let's start the Food API frontend with HTML, Bootstrap 5, and Vanilla JavaScript: I'll prepare the base interface structure to display, insert, and manage food products by consuming the REST API.

Guarda lezione

I'll walk you through solving CORS issues in Spring Boot: I'll explain what CORS policies are, why the browser enforces them, and how to configure them correctly using a @Bean configuration class.

Guarda lezione

We'll complete the GET fetch to display food products in a table on the frontend and start handling the insert modal with JavaScript, giving the Food API client its first fully working shape.

Guarda lezione

I'll implement data saving via fetch POST triggered from the Bootstrap modal: the HTML form sends the DTO to the Spring Boot controller, which persists the new food item in real time.

Guarda lezione

We'll add DELETE and PUT to the Food API frontend: users can delete products with a click and update them from the HTML modal using well-structured fetch calls against the Spring Boot REST API.

Guarda lezione

We close out the Food API by completing the DELETE and PUT operations from the frontend, wrapping up the full CRUD with Spring Boot and testing every operation from the web interface against the Java backend.

Guarda lezione
Giovanni Pace

Giovanni Pace

Ingegnere Informatico · Pratola Peligna

  • 107 Courses
About the teacher

Sono un ingegnere informatico con oltre 15 anni di esperienza nel settore ICT. Mi occupo di sviluppo software, cybersecurity, data science e intelligenza artificiale, con particolare attenzione all’innovazione e all’automazione dei processi aziendali. Da anni svolgo anche attività di docenza e formazione, creando percorsi pratici e coinvolgenti su programmazione, DevOps, AI e sicurezza informatica.

This course includes

  • Lessons 29
  • Duration 5h 10m
  • Difficulty intermedio
  • Language it
  • Certificate No

Recently viewed