About Us Contact Us Write for Us Advertise
Home > Java > Build a Spring Boot REST API Project (Step by Step)
Java

Build a Spring Boot REST API Project (Step by Step)

Build a complete Spring Boot REST API project for managing tasks: entity, repository, service, and controller with full CRUD, plus how to test it and make it portfolio-ready.

Shiv Pandey
Shiv Pandey
Oct 12, 2026 | 109 views
Build a Spring Boot REST API Project (Step by Step)

Ready to build a real backend? In this project you'll create a complete Spring Boot REST API for managing tasks — the kind of thing that powers actual apps and impresses in interviews. We'll assemble everything from the Spring Boot roadmap into one working project. Build this, put it on GitHub, and you have something concrete to demo.

What you'll build: a Task API with full CRUD (create, read, update, delete) endpoints backed by a database. You'll use the layered architecture — Controller → Service → Repository — that professional apps rely on. Prerequisite: comfort with the REST API and JPA lessons.

Step 1: Create the project

Generate a project on start.spring.io with these dependencies: Spring Web, Spring Data JPA, and a database driver (H2 for a quick start, or PostgreSQL for the real thing). Open it in your IDE.

Step 2: The entity

Model the data we're storing — a Task — as a JPA entity:

@Entity
public class Task {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    private boolean completed;
    // getters and setters (or Lombok @Data)
}

Step 3: The repository

One empty interface gives you full database access — the magic of Spring Data JPA:

@Repository
public interface TaskRepository extends JpaRepository<Task, Long> { }

Step 4: The service (business logic)

Keep logic out of the controller — put it in a service. This is the layering best practice:

@Service
public class TaskService {
    private final TaskRepository repo;
    public TaskService(TaskRepository repo) { this.repo = repo; }

    public List<Task> findAll() { return repo.findAll(); }
    public Task findById(Long id) {
        return repo.findById(id)
            .orElseThrow(() -> new RuntimeException("Task not found"));
    }
    public Task save(Task task) { return repo.save(task); }
    public void delete(Long id) { repo.deleteById(id); }
}

Step 5: The REST controller

Expose the endpoints. Each maps an HTTP method to a service call:

@RestController
@RequestMapping("/api/tasks")
public class TaskController {
    private final TaskService service;
    public TaskController(TaskService service) { this.service = service; }

    @GetMapping
    public List<Task> all() { return service.findAll(); }

    @GetMapping("/{id}")
    public Task one(@PathVariable Long id) { return service.findById(id); }

    @PostMapping
    public Task create(@RequestBody Task task) { return service.save(task); }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) { service.delete(id); }
}

Step 6: Run and test it

Start the app and hit your API. You can use a browser for GETs, or a tool like Postman / curl for the rest:

# create a task
curl -X POST http://localhost:8080/api/tasks \
  -H "Content-Type: application/json" \
  -d '{"title":"Learn Spring Boot","completed":false}'

# list all tasks
curl http://localhost:8080/api/tasks

You'll get JSON back. Your API is live and persisting data — congratulations, you've built a real backend service! 🎉

Make it portfolio-ready

Building my first full CRUD API was the moment backend development truly clicked — assembling controller, service, repository, and a database into something a frontend could actually talk to felt like crossing a threshold. My advice: build the bare-bones version above first and confirm it works end to end before adding validation, error handling, or tests. Getting one full request-to-database round trip working is the milestone; everything else is polish you layer on. This project is essentially a scaled-down version of what powers real apps (including this website), so once you've built it, you understand the shape of professional backends. Push it to GitHub and talk about it in interviews.

Next projects

← Spring Boot roadmap · More project ideas →

Related Articles

Build a Blog Platform with Spring Boot (Capstone Project)
Java

Build a Blog Platform with Spring Boot (Capstone Project)

Build a Spring Boot CRUD App with a Database (Step by Step)
Java

Build a Spring Boot CRUD App with a Database (Step by Step)

Building a REST API with Spring Boot (Beginner Guide)
Java

Building a REST API with Spring Boot (Beginner Guide)

Build Your First Spring Boot App (Step-by-Step Beginner Guide)
Java

Build Your First Spring Boot App (Step-by-Step Beginner Guide)