Featured Article

Build a Spring Boot REST API Project Tutorial: Step by Step Guide

Kenneth Jul 13, 2026

Spring Boot offers a robust framework for creating stand-alone, production-grade Java applications. One of its key features is the ease with which it enables building RESTful APIs. If you're looking to dive into Spring Boot REST API development, you're in the right place. This comprehensive tutorial will guide you step-by-step through creating a simple but powerful Spring Boot REST API project.

WebClient In Spring Boot
WebClient In Spring Boot

Before we start, make sure you have Java Development Kit (JDK) 8 or later, Apache Maven or Gradle, and your favorite IDE set up on your machine. We'll also use Spring Boot version 2.4.5 for this project.

Learn Spring Boot by Annotations
Learn Spring Boot by Annotations

Project Setup

Let's begin by setting up a new Spring Boot project. We'll use Spring Initializr, an online tool that simplifies project generation.

Java Spring boot MongoDB REST API | VS Code | Docker | Springfox
Java Spring boot MongoDB REST API | VS Code | Docker | Springfox

Navigate to the Spring Initializr webpage, choose 'Maven Project' or 'Gradle Project' based on your preference, select 'Spring Web' as a dependency, and click on 'GENERATE'. This will create a basic Spring Boot project with the necessary dependencies for a REST API.

Project Structure

How to create RESTful Web Services in Java using Spring Boot? Example Tutorial
How to create RESTful Web Services in Java using Spring Boot? Example Tutorial

Once downloaded, you'll find the generated project has a clean and simple structure. The main files and folders to note are:

  • src/main/java:Contains the main application class (usually named 'SpringBootRestApiApplication.java') and packages for your application's code.
  • src/main/resources:Houses application.properties or application.yml for configuration, along with static files like HTML or CSS.

Creating the REST API

Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed
Master CRUD Operations: Spring Boot and Spring Data JPA Unleashed

Now that we have our project set up, let's create a simple REST API with a single endpoint to return a greeting message. Create a new class named 'GreetingController' in the default package.

Here's a basic example of what the 'GreetingController' class might look like:

```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class GreetingController { @GetMapping("/greeting") public String greeting() { return "Hello, Spring Boot REST API!"; } } ```

The '@RestController' annotation indicates that this class is a controller that handles HTTP requests. The '@GetMapping' annotation maps the HTTP GET request to the 'greeting' method. When accessed at http://localhost:8080/greeting using your browser or tools like Postman or curl, it will return the string "Hello, Spring Boot REST API!".

Spring Boot Tutorial
Spring Boot Tutorial

Testing the API

To test our API locally, we'll use an embedded Tomcat server that Spring Boot provides out of the box. You can run your application using your IDE or via the command line with 'mvn spring-boot:run' or 'gradle bootRun'.

Building your first REST API: Java and Spring Boot
Building your first REST API: Java and Spring Boot
Spring Boot Security and JWT
Spring Boot Security and JWT
How To Handle Exceptions & Errors In Spring Boot?
How To Handle Exceptions & Errors In Spring Boot?
How Spring MVC Framework works? How HTTP Request is processed?
How Spring MVC Framework works? How HTTP Request is processed?
How to Build Scalable and Secure Microservices with Spring Boot: A Comprehensive Tutorial
How to Build Scalable and Secure Microservices with Spring Boot: A Comprehensive Tutorial
What Is Spring Boot in Java? Beginner Guide 2026
What Is Spring Boot in Java? Beginner Guide 2026
Spring Boot + RESTful + JUnit + Mockito + Hamcrest + EclEmma
Spring Boot + RESTful + JUnit + Mockito + Hamcrest + EclEmma
7 Reasons to use Spring Framework for Creating RESTful Webservices  in Java
7 Reasons to use Spring Framework for Creating RESTful Webservices in Java
Spring with Maven BOM | Baeldung
Spring with Maven BOM | Baeldung

Accessing the API

Once your application is running, open your browser or Postman and navigate to http://localhost:8080/greeting. You should see the greeting message returned by our API.

You can also use curl, a command-line tool, to test the API. Open a terminal or command prompt and type:

```bash curl http://localhost:8080/greeting ```

You should see the greeting message printed out.

Congratulations! You've just created your first Spring Boot REST API. You can build upon this foundation to add more endpoints, handle HTTP methods like POST, PUT, and DELETE, and even include request and response objects in JSON format.

Explore and learn more about Spring Boot's capabilities to create robust, scalable, and maintainable REST APIs. Happy coding!