Hey there welcome back friends in our last video we were facing some kind of issue where we are able to fetch the information properly but when we are trying to post some information and then fetching the information we are getting the old list only, somehow the information is not getting added into our list. And in order to fix this, we need to navigate to our application and need to check how the list as laid out in our service layer. Now in here, our list is what our list is a normal variable is a list of objects and it is initialized using this particular constructor. Now this way of handling thing is not good enough for our situation because this particular variable is dependent on objects and when it comes to Data data should be a singleton thing, right? A data needs to have only one copy, when we connect with the database in the database, there would be only one copy which is shared among our application.
So, similarly, we need to implement some kind of logic so that we can mimic the scenario which is presented by a database. So, first of all, we must get rid of this constructor and we must initialize this list right away and the way is very simple. In between pair of parenthesis in here people make use of something known as arrays.as list. So if I make use of this particular class areas, we have like couple of things in here one of the thing is as list and we can convert an array into a list, so let us do that. So in between this pair of paranthesis letters, do couple of For small little changes. Here we go.
So this looks good to me. And we don't need it this particular constructor now. All right, so this is good enough. Now the initialization part, and the declaration part is done at all one place. So will this fix our issue? Let me stop the web server.
And let me rerun this application, the Embedded Web Server will start in a couple of seconds. All right, let me navigate to Google Chrome. And let me send in the request and here is our result. Let me post a value. Sure as the output there is no error. Let me again get the list.
And here we go. Again, there is this issue. We are not able to see the element added into the list again, why it happened? It happened because our list is not a static list there are like multiple copies of this particular list created based on the object in the background as a result in order to make only one copy for this class we will mark this as a static and we will relaunch this application. Let me show you the console. This will take couple of seconds the Embedded Web Server is up and running.
Let me navigate to postman and let me again show you the list here is the list that we post an element here is the sample data and the header is already there using this history it is very convenient to send in the request from the history. Let me click on Send again there is no error. And now if I get the list, we get the answer. We are able to post the element in our Less amazing. So this is how we have fixed the issue and in our next video we will see couple of more things. Couple of more functionality implemented by us for our micro service.
All right, so that's it for today. I hope you guys enjoyed this video. Thanks for watching. Have a nice day and take care