Hackforge Academy

Category: spring_boot

Spring Boot rest api

Published on 21 Jun 2026

Explanation

Spring Boot simplifies REST API development by providing auto-configuration, embedded Tomcat server, and starter dependencies. A REST API allows applications to communicate over HTTP using resources represented as JSON.

Code:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(
Application.class, args);
    }
}

Explanation

The @RestController annotation marks a class as a REST controller. Methods inside this class automatically return data as the HTTP response body instead of rendering a view.

Code:

@RestController
public class HelloController {

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

Explanation

The @GetMapping annotation maps HTTP GET requests to a specific method. When a client sends a GET request to the specified URL, the method executes and returns a response.

Code:

@GetMapping("/welcome")
public String welcome() {
    return "Welcome to REST API Development";
}

Explanation

Spring Boot automatically converts Java objects into JSON format using the Jackson library. This makes it easy to build APIs that return structured data.

Code:

public record User(Long id, String name) {}

@GetMapping("/user")
public User getUser() {
    return new User(1L, "Praveen");
}

Explanation

Once the application is started, the embedded Tomcat server hosts the API. Clients can access endpoints using a browser, Postman, or frontend applications.

Code:

GET http://localhost:8080/hello

Response:
Hello Spring Boot

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community