Getting Started with Spring Boot: Your First "Hello, World!" REST API

I'm a tech enthusiast who loves building backend systems that just work — clean, scalable, and efficient. I've worked with microservices, Spring Boot, Azure, and APIs, and I enjoy digging into root causes and making systems better. Whether it's writing clean code, reviewing it, or managing deployments with DevOps tools, I'm always up for the challenge. I like working in collaborative environments where I can learn, share, and grow alongside smart people.
👋 Introduction
Spring Boot makes it easy to create stand-alone, production-grade Spring applications with minimal setup. In this guide, you’ll learn how to build your first Spring Boot REST API that responds with a simple "Hello, World!".
🛠️ Step 1: Create a Spring Boot Project
The easiest way to generate a Spring Boot project is by using Spring Initializr:
🔧 Configuration:
Project: Maven
Language: Java
Spring Boot: (Use the latest stable version)
Dependencies: Spring Web
Package name:
com.helloworldor anything you would like
The configuration should look like this:

Click Generate, unzip the downloaded file, and open it in your favourite IDE (IntelliJ IDEA, Eclipse, VS Code). I prefer to use IntelliJ IDEA.
📁 Step 2: Understand the Project Structure
Spring Boot projects follow a standard structure:
src
└── main
├── java
│ └── com.helloworld
│ ├── HelloWorldApplication.java
└── resources
├── application.properties
HelloWorldApplication.javais your entry point which contains a main method.We'll create a
HelloWorldController.javato handle HTTP requests.
👨💻 Step 3: Create the Controller
Inside src/main/java/com/helloworld, create a file named HelloWorldController.java:
package com.helloworld;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@GetMapping("/hello-world")
public String helloWorld() {
return "Hello, World!";
}
}
@RestController = @Controller + @ResponseBody
In Spring Boot,
@RestControlleris a convenience annotation that combines two annotations:@Controller:Marks the class as a Spring MVC controller that can handle HTTP requests.
By default, methods in a class annotated with
@Controllerreturn views (e.g., HTML pages via Thymeleaf or JSP).If you return a string, it tries to resolve it as a view name — not ideal for REST APIs.
@ResponseBody:Tells Spring to write the method’s return value directly to the HTTP response body, instead of interpreting it as a view name.
Useful when you want to return plain text, JSON, or XML from a controller method.
So, when you write:
@RestController
public class HelloController {
...
}
It’s functionally equivalent to:
@Controller
@ResponseBody
public class HelloController {
...
}
@GetMapping("/hello")Maps GET Requests to/hello@GetMapping("/hello")is a specialized version of the more generic@RequestMapping(method = RequestMethod.GET, path = "/hello").It tells Spring to:
Map HTTP GET requests sent to the path
/helloTo the Java method it annotates.
So, for this method:
@GetMapping("/hello")
public String helloWorld() {
return "Hello, World!";
}
When someone makes a GET request to http://localhost:8080/hello, Spring will:
Route the request to the
helloWorld()methodExecute it
Return the response
"Hello, World!"as the body of the HTTP response
▶️ Step 4: Run the Application
You can run your app in multiple ways:
📦 Using Maven:
./mvnw spring-boot:run
🧠 Or from your IDE:
Right-click on HelloWorldApplication.java → Run.
You’ll see logs ending with:
Tomcat started on port(s): 8080 (http)
8080 is the default port that spring boot uses to run the application. You can change it by setting following property in application.properties file:
server.port=9099
or in application.yml file:
server:
port:9099
🌐 Step 5: Test the Endpoint
Open your browser or Postman and go to:
http://localhost:8080/hello-world
✅ Output:
Hello, World!
🧠 Bonus: What Just Happened?
Spring Boot auto-configured an embedded Tomcat server.
The
@RestControllerhandled your HTTP request.You didn’t need to write any XML configuration.
🧩 What’s Next?
Now that you’ve set up your first GET endpoint, here are a few ideas for the next steps:
✅ Accept query parameters
✅ Return JSON responses
✅ Add logging
✅ Connect to a database
🔚 Conclusion
You just created your first Spring Boot application with a simple REST endpoint. Spring Boot handles a lot of boilerplate for you so you can focus on building features.
You can find the complete code here: GitHub - AmanVW
Stay tuned for the next part in the series!
© Aman Walke



