Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 17

    CRUD API Development

    Time to ship a real CRUD API: Create, Read, Update, Delete for a Product resource — the workhorse pattern of every backend job interview.

    Course progress0%
    Focus
    2 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Time to ship a real CRUD API: Create, Read, Update, Delete for a Product resource — the workhorse pattern of every backend job interview.

    Informative example

    Controller, service, repository — full vertical slice:

    ts
    // Entity
    @Entity @Table(name = "products")
    public class Product {
    @Id @GeneratedValue Long id;
    @Column(nullable = false) String name;
    @Column(nullable = false) int priceCents;
    // getters / setters or use Lombok @Data
    }
    // Repository
    public interface ProductRepository extends JpaRepository<Product, Long> {
    Page<Product> findByNameContainingIgnoreCase(String q, Pageable p);
    }
    // DTOs
    record ProductDto(Long id, String name, int priceCents) {}
    record NewProduct(@NotBlank String name, @Positive int priceCents) {}
    // Service
    @Service @Transactional
    public class ProductService {
    private final ProductRepository repo;
    public ProductService(ProductRepository repo) { this.repo = repo; }
    public ProductDto create(NewProduct cmd) {
    var saved = repo.save(new Product(cmd.name(), cmd.priceCents()));
    return new ProductDto(saved.getId(), saved.getName(), saved.getPriceCents());
    }
    // findById, update, delete ...
    }
    // Controller
    @RestController @RequestMapping("/api/v1/products")
    class ProductController {
    private final ProductService svc;
    // ... GET / POST / PUT / DELETE wired to svc
    }
    Ready to mark this lesson complete?Track your journey across the entire course.