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");
}