
Java : Build a REST API with Spring Boot and PostgreSQL
Oddly Yogi · 11 lượt xem · 13 thg 11, 2026
Mô tả
The Shelf library app finally serves other apps: in this video we build a REST API with Spring Boot 4 and PostgreSQL 18. Like the front desk of a library, an API takes requests at one window, checks them, and answers in an agreed format. We generate the project with Spring Initializr, configure the datasource, create tables with Flyway migrations, map a JPA entity, query it with a Spring Data repository and a derived query, put the rules in a transactional service, and expose endpoints with @RestController, @GetMapping and @PostMapping. We validate input with Bean Validation, return errors as ProblemDetail, and walk through the API with curl: create with 201 and a Location header, 400, 404 and 409. Then we test it with @WebMvcTest, @MockitoBean and @SpringBootTest against the real database, build a runnable jar, and write a Dockerfile and compose.yaml.
Versions: Java 25 LTS (Eclipse Temurin 25.0.5), Spring Boot 4.1.2, PostgreSQL 18, Apache Maven 3.10.0.
In this chapter:
00:00 A front desk for the library
01:41 Generating the project
03:30 The application class and its settings
05:17 Tables with Flyway
06:39 A JPA entity
08:02 A Spring Data repository
08:58 The service layer
10:13 The REST controller
12:03 Errors as problem details
13:36 Running the API
16:03 Testing the API
18:49 Shipping it in containers
20:22 Wrap up
This is Chapter 15 of 15 in the "Java" series.
#Java #SpringBoot #PostgreSQL #RESTAPI #LearnJava