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.
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.
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
- Add validation with
@Validso bad input is rejected. - Add global exception handling for clean error responses.
- Add an
update(@PutMapping) endpoint. - Switch H2 for PostgreSQL and deploy it for a live demo link.
- Write a couple of tests — hugely impressive on a junior portfolio.
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.