Hackforge Academy

Category: spring_boot

REST Architecture in Spring Boot

Published on 21 Jun 2026

Explanation

REST (Representational State Transfer) is an architectural style used to build scalable web services. In Spring Boot, REST APIs expose resources through URLs and communicate using HTTP methods such as GET, POST, PUT, and DELETE.

Code:

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

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

Explanation

A resource is any data exposed by a REST API. Resources are identified using unique URLs. For example, '/users' represents a collection of users, while '/users/1' represents a specific user.

Code:

@RestController
@RequestMapping("/users")
public class UserController {

    @GetMapping
    public String getUsers() {
        return "All Users";
    }
}

Explanation

REST APIs are stateless, meaning the server does not store client session information between requests. Each request must contain all the information needed to process it.

Code:

@GetMapping("/profile")
public String getProfile(
@RequestHeader("Authorization") 
String token) {
    return "Processing request 
using token: " + token;
}

Explanation

REST architecture uses HTTP methods to perform operations on resources. GET retrieves data, POST creates data, PUT updates data, and DELETE removes data.

Code:

@PostMapping
public String createUser() {
    return "User Created";
}

@DeleteMapping("/{id}")
public String deleteUser(
@PathVariable Long id) {
    return "User Deleted";
}

Explanation

REST APIs typically exchange data in JSON format. Spring Boot automatically converts Java objects into JSON responses using the Jackson library.

Code:

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

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

๐Ÿš€ 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