Spring Boot Getting Started: Build Your First REST API

From zero to a running REST API with Spring Boot 3—dependencies, controllers, and dependency injection.

Spring Boot is the fastest way to get a production-ready Java app running. Here’s how to build your first REST API.

Spring Boot and Java backend
Spring Boot and Java backend

Setup

  • start.spring.io — Generate a project with Spring Web (and optionally JPA, Lombok). Choose Java 21 and the latest Boot 3.x.
  • Structure — Main class with @SpringBootApplication; put controllers, services, and entities in packages under the main package.
  • Runmvn spring-boot:run or run the main class from your IDE. The app starts an embedded Tomcat (default port 8080).

First endpoint

Create a class with @RestController and @RequestMapping("/api"). Add a method with @GetMapping("/hello") that returns a DTO or String. Spring serializes to JSON by default. Inject a service with @Autowired (or constructor injection) for business logic.

Spring Boot adoption (Java backend survey):

Java web framework usage

Next steps

Add Spring Data JPA for persistence, application.yml for config, and Spring Security for auth. Use the official guides and start.spring.io to add only what you need.

A full Spring Boot tutorial:

Takeaway

Spring Boot’s convention-over-configuration and auto-configuration get you from zero to API quickly. Learn the core: dependency injection, controllers, and the application lifecycle.