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