Member-only story
Making a RESTful API Creation Easy in Spring Boot
Explore the Feign client and other useful libraries
Have you ever had the trouble of making an HTTP request to several different Application Programming Interfaces (APIs)? Wouldn’t it be easier to combine only what you need from these different APIs into a single API?
Creating a middleware can solve this issue. A software application middleware allows us to have a single customized source of data. One of the major benefits of having a middleware is that it connects many different products and services together in a shared system. So, what exactly is a middleware? According to Microsoft Azure, a middleware is a software operating as a hidden translation layer between the operating system and the application running on it. It provides data management and communication for distributed applications.
In this article, I will be demonstrating how to create a middleware using Spring Boot with the aid of some dependencies such as the Feign client. Feign is a declarative web service created by Netflix that provides a high degree of abstraction for making Representational State Transfer (REST) API calls. Likewise, it removes the need to write basic HTTP request codes while simultaneously providing efficiency and neatness to source code.
For simplicity’s sake, we will be making calls to a single fake online REST API service used for testing and prototyping called JSONPlaceholder. Visit https://jsonplaceholder.typicode.com/ to see the different available routes. I will be using the “todo” route for this exercise.
At the end of this article, the reader should understand what a middleware is and know when and how to use one. Likewise, they should become familiar with the Feign web service client.
If you are new to Spring or just need a refresher, consult this article that explains a few basic concepts.
Let’s Begin!
Firstly, we need to create a Spring Boot project. To do so, we will use Spring Initializr. The screenshot below highlights the configurations and dependencies we will be using. For now, let’s keep it simple by using only the Spring Web dependency. We’ll add all the other dependencies manually for our project as we progress…