Better Programming

Advice for programmers.

Follow publication

Member-only story

Building a Spring Boot REST API — Part 2: Working With Controllers and Responses

Salisu Wada
Better Programming
Published in
4 min readDec 11, 2017

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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Salisu Wada
Salisu Wada

Written by Salisu Wada

A busy researcher. Squeezing the little time I have to write #code

Responses (10)

Write a response