Spring Boot is an opinionated layer on top of the Spring Framework that removes most of the boilerplate configuration. With a few annotations and a handful of classes, you can have a fully functional REST API running locally. Here's how.
1. Bootstrap the Project
The fastest way is Spring Initializr at start.spring.io. Select:
- Project: Maven
- Language: Java
- Spring Boot: 3.x (latest stable)
- Dependencies: Spring Web
Download, unzip, and open in your IDE. You'll see a single DemoApplication.java with a main method. That's your entry point.
2. Create Your First Controller
Create a new file HelloController.java in the same package:
package com.example.demo; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api") public class HelloController { @GetMapping("/hello") public String hello() { return "Hello from Orbit Studios!"; } }
Run mvn spring-boot:run and hit http://localhost:8080/api/hello. You should see the response immediately.
3. Return JSON with a Model
Create a simple record to represent your data:
public record Course(
Long id,
String title,
String description
) {}Now update the controller to return a list:
@GetMapping("/courses") public List<Course> getCourses() { return List.of( new Course(1L, "Spring Boot Basics", "Learn the fundamentals"), new Course(2L, "REST API Design", "Build clean APIs") ); }
Spring Boot automatically serialises the list to JSON using Jackson — no configuration needed.
4. Handle Path Variables and Request Bodies
// GET /api/courses/1 @GetMapping("/courses/{id}") public Course getCourse(@PathVariable Long id) { return new Course(id, "Sample", "Description"); } // POST /api/courses @PostMapping("/courses") @ResponseStatus(HttpStatus.CREATED) public Course createCourse(@RequestBody Course course) { // In a real app, save to database here return course; }
5. Key Annotations to Know
- @RestController — marks the class as a REST controller, combines @Controller and @ResponseBody
- @RequestMapping — sets the base path for all endpoints in the class
- @GetMapping / @PostMapping / @PutMapping / @DeleteMapping — maps HTTP methods to handler methods
- @PathVariable — extracts a value from the URL path
- @RequestBody — deserialises the request JSON body into a Java object
- @ResponseStatus — sets the HTTP response status code
What's Next
This is the foundation. From here the natural next steps are: connecting to a database with Spring Data JPA, adding input validation with @Valid and Bean Validation, and securing your endpoints with Spring Security.
Our full Spring Boot for Beginners course covers all of this with hands-on projects from day one.