Spring provides RESTful web service implementations with its web MVC module. With each annotation, the creation of a REST web service is more or less like web MVC architecture. The RESTful web services can be built with the help of a REST controller. The noticeable difference between a web MVC and REST controller is the way they create the HTTP response.
A traditional web MVC uses various view technologies (such as JSP, Thymeleaf, and so on) to build a response, while the REST controller returns objects that are converted into JSON (or XML, based on the configuration), and finally sent as a HTTP response. For our Blogpress application, we will use RESTful services in the following two use cases:
- Showing blog lists on the home page
- Showing blog comments when a particular blog is open for view
To achieve this, we will write new controller class as follows:
@RestController @RequestMapping("api") public class BlogRESTController { private Logger...