Beginner’s Guide to Spring Boot: Your First REST API

Himanshu JhaHimanshu Jha
4 min read

What is Spring Boot?

Spring Boot is one of the most popular frameworks for building Java-based web applications. It simplifies the process of creating production-ready applications with minimal configuration.

It’s built on top of the widely used Spring Framework and is designed to simplify the bootstrapping and development of new Spring applications.

Traditionally, setting up a Spring application required a lot of boilerplate code, XML configurations, and manual dependency setup(s). Spring Boot revolutionizes this process by offering:

  • Auto-configuration: Automatically configures your application based on the libraries in your classpath.

  • Standalone Applications: Eliminates the need for deploying WAR files by embedding servers like Tomcat or Jetty directly.

  • Opinionated Defaults: Provides default configurations to help you get started quickly without needing to make every decision from scratch.

  • Production-Ready Features: Includes built-in tools like health checks, metrics, and externalized configurations.

Whether you’re building microservices, REST APIs, or full-stack enterprise applications, Spring Boot provides a fast and powerful way to get started with minimal effort.

Why Should You Learn Spring Boot?

Spring Boot stands out as a preferred choice for Java developers. Here's why it's worth learning:

1. Rapid Development

Spring Boot eliminates the need for complex XML configurations and boilerplate setup. You can get a web application up and running in minutes using embedded servers like Tomcat or Jetty.

2. Microservice-Ready Architecture

Spring Boot is ideal for building microservices. With features like embedded web servers, externalized configuration, and integration with Spring Cloud, it's well-suited for scalable, distributed applications.

3. Powerful Ecosystem

It integrates seamlessly with other Spring modules:

  • Spring Data JPA for database access

  • Spring Security for authentication and authorization

  • Spring Cloud for distributed systems

4. Production-Ready Features

Out of the box, Spring Boot includes:

  • Health checks

  • Metrics and monitoring tools

  • Externalized configuration

  • Logging and error handling

5. Massive Community and Documentation

Spring Boot has one of the largest Java developer communities. It’s well-documented and actively maintained, so help is always just a click away.

6. Career and Industry Relevance

Spring Boot is widely used in the industry, from startups to large enterprises. Learning it significantly improves your chances of landing backend development roles.

Prerequisites

Before getting started, ensure you have the following installed:

  • Java JDK 17 or later

  • Maven or Gradle

  • An IDE (IntelliJ IDEA, Eclipse, or VS Code)

  • Internet connection (to download dependencies)

Step 1: Create a Spring Boot Project

Visit Spring Initializr and configure your project:

  • Project: Maven

  • Language: Java

  • Spring Boot: 3.1.x or latest

  • Group: com.example

  • Artifact: demo

  • Dependencies:

    • Spring Web

Click Generate, unzip the project, and open it in your IDE.

Step 2: Understand the Project Structure

Your project structure will look like this:

src
 └── main
     └── java
         └── com.example.demo
             └── DemoApplication.java
     └── resources
         └── application.properties

DemoApplication.java is the entry point for your Spring Boot app.

Step 3: Create a Simple REST Controller

Inside the com.example.demo package, create a new file named HelloController.java:

package com.example.demo;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring Boot!";
    }
}

This creates a GET endpoint at /api/hello.

Step 4: Run the Application

You can run the app in several ways:

  • IDE: Right-click DemoApplication.java → Run

  • Terminal:

./mvnw spring-boot:run

Once the app is running, go to:
http://localhost:8080/api/hello

You should see:

Hello, Spring Boot!

Step 5: Test Using Postman or Browser

  • Browser: Visit the URL above.

  • Postman / curl:

curl http://localhost:8080/api/hello

Optional: Return JSON Instead of Plain Text

Modify your controller to return an object:

@GetMapping("/greet")
public Map<String, String> greet() {
    Map<String, String> response = new HashMap<>();
    response.put("message", "Welcome to Spring Boot!");
    return response;
}

Output:

{
  "message": "Welcome to Spring Boot!"
}

Conclusion

You just built your first REST API using Spring Boot! 🎉

In this beginner-friendly journey, you created a working REST API using Spring Boot from scratch. You started by generating a Spring Boot project using Spring Initializr, understood the structure of a typical Spring Boot application, and wrote a simple REST controller that responds with both plain text and JSON. Most importantly, you saw how easy and fast it is to get up and running with Spring Boot compared to the traditional Spring setup.

This hands-on experience introduced you to several core concepts:

  • Dependency management with Spring Initializr

  • Annotation-driven development using @RestController, @RequestMapping, and @GetMapping

  • Running and testing your API locally

  • Returning JSON responses, which is foundational for building scalable backend services

But this is just the tip of the iceberg.

Spring Boot is designed to reduce boilerplate and let developers focus on writing business logic; however, it also features powerful capabilities that make it a robust framework for production-grade applications. From database integration and authentication to exception handling and deployment, there’s a lot more to explore.

You can now explore:

  • Creating POST, PUT, and DELETE endpoints

  • Connecting to a database

  • Using services and repositories

Happy coding! ✨

1
Subscribe to my newsletter

Read articles from Himanshu Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Himanshu Jha
Himanshu Jha

Software Developer with 4+ years of experience in application development, proficient in Python, Java, ReactJS, and React Native. Successfully delivered several complex applications, demonstrating strong problem-solving and technical expertise.