Java Academy · Lesson

Mini Project: REST API

Build a small REST API with DTO, controller, and service.

Lesson 3 of 38 steps

Mini Project: REST API is a free Java Academy lesson on CoddyKit. This is lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, and your progress syncs across the web and the CoddyKit app. The Java Academy course includes 3 lessons in total.

Intro

Mini project: Build a simple REST API to manage users. You will create a DTO, controller, and service.

Code: DTO

Start with a DTO to represent the user data.

public class UserDto {
  private String name;
  private int age;
  // getters and setters omitted for brevity
}

Code: Service

A service holds business logic and stores users in memory.

import java.util.*;import org.springframework.stereotype.Service;
@Service
public class UserService {
  private List<UserDto> users = new ArrayList<>();

  public List<UserDto> getAll() { return users; }
  public void add(UserDto u) { users.add(u); }
}

Code: Controller

The controller exposes REST endpoints for listing and adding users.

import org.springframework.web.bind.annotation.*;import java.util.*;@RestController
@RequestMapping("/users")
public class UserController {
  private final UserService service;
  public UserController(UserService service) { this.service = service; }

  @GetMapping
  public List<UserDto> all() { return service.getAll(); }

  @PostMapping
  public void add(@RequestBody UserDto dto) { service.add(dto); }
}

Run & test

Run the app, then test with curl -X POST and GET /users. You should see user data in JSON.

Improvements

You can extend this by adding validation, unique IDs, or persistence with a database later.

REST controller check

Quick check: Which annotation marks a class as a REST controller in Spring Boot?

Recap

Recap: Built a REST API with DTO, service, and controller. Tested endpoints with JSON.

Free to start

Learn Java with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
104
Lessons
374

Frequently Asked Questions

Is the “Mini Project: REST API” lesson free?

Yes — the full text of “Mini Project: REST API” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO. The Java Academy course includes 3 lessons in total.

What will I learn in “Mini Project: REST API”?

Build a small REST API with DTO, controller, and service. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.

How long does the “Mini Project: REST API” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Project Setup & Starters
  2. DTOs & Validation
  3. Mini Project: REST API
← Back to Java Academy