Member-only story
Building a Spring Boot REST API — Part 2: Working With Controllers and Responses
Extending the blog controller to contain the required functionalities

In the previous tutorial, we set up a Spring Boot application with a single dummy controller.
In this tutorial, we will extend the “blog controller” to contain the required functionalities.
Blog Item Class
The “blog controller” function is to save, update, delete, and fetch blog items. Therefore, we need to have a blog item class, containing the blog properties. These properties should correspond to the columns in the “blog table”.

- The class must also have a default constructor. Notice that I have two, in this case.
- I’ve also implemented a
toString()
method for printing the class content.
Blog Data
Ideally, an individual blog post will be fetched from a database table, similar to the one showed above.
We will not work with a database at this point. A class to simulate the database functionality will be created and later substituted with the actual implementation

- The class will contain a list of hard-coded blog posts.
- The class must be a singleton so that changes can be persisted across different HTTP requests.
Singlewhat? According to Wikipedia, a singleton is a design pattern used in object-oriented programming to permit no more than one instance of a class.
In other words, if a class is a singleton, you can only have one instance of that class throughout the…