Shubham Deshmukh
3 min readJul 6, 2022

Getting Started | Building an Application with Spring Boot

Writing my first REST API using Spring Boot.

Hello Friends, Today we will understand and write our Spring Boot REST API from scratch. We will go through the pre-requisites and later will write the code.

Tip : If you are new to java, Please visit this link to have better understanding of Java.

The requirement for running our first Spring Boot Application.

For executing any Spring Boot program, the following steps must be followed.

Creating Spring Boot Project

Navigate to https://start.spring.io/ in your favorite browser. This is spring intializr which helps us to create a skeleton for our application.

  • Add project metadata as you like or you can refer to the screenshot below.
  • Choose either Maven and packaging as jar.
  • Click Dependencies and select Spring Web.
  • Click Generate and a Zip will be downloaded. This will contain all the required files for your project like the main class and pom.xml
  • unZip the Package and Import the project in IDE.
  • Once you import give some time to maven to import the required libraries. The project will look like the below once all dependencies are imported.
  • Now create a package with the name Controller.
  • Now that the package is ready we will add a controller to our application. create a new class with the name HelloController.java.

Add the below code to the class.

package com.example.FirstAPI.Controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
  • Run the application.

Suppose you are not getting the option to run the application as a spring boot application. Run it as a Java Application and give FirstApiApplication.java as an entry point.

  • Output Logs

Our Application is UP.

Running the API.

Go to the browser and hit http://localhost:8080/

Thanks for reading. I hope this story was helpful. If you are interested,

check out my other articles.

you can also visit shubhamdeshmukh.com.

GitHub: https://github.com/sd2995/SpringBoot/tree/main/FirstAPI

Shubham Deshmukh
Shubham Deshmukh

Written by Shubham Deshmukh

Software Developer | Cloud infrastructure | IaC | AWS | DevOps | Hit the follow button for Cloud-related content 😄