Now let's see how to add a POST request to our Express application, we are going to add the search feature. To do so, we create an app dot POST method in which we are going to call the articles dot search method that we are going to implement with the req dot body. As a parent, please validate the user input before using it. So now let's go to create this the search method in the articles class. We will have some problems the first one is on the stock that shows only stock articles if and only if there is the in stock Param set to one. Then we are going to filter for type so if there is a type program in the req dot body object, we are going to show all the articles with that Given type, sings, same concept for title.
So if there is a title Param in our req dot body object, we are going to filter or the articles that whose title contains the title bar. So, using the filter method on the on our article list, we are going to test for all the problems we have. This is the title. Now, let's add even the type because it's quite similar. Please add all the tests you want, for example, the price range and stuff like that. And now if the result is an empty is an empty array, we just reject with our narrow response.
We status code, code and message set accordingly. Otherwise, we are going to return a success response whose payload is set to the list to the author of the list. So now please remember to stop our node instance if you have a running one and started again. Now let's do a POST request with curl within the search endpoint setting the content type to application JSON and passing a type T shirt. The result will be a list of two articles, one that is in stock and one is not in stock. So let's filter on the in stock articles pass in a stock Param.
As you can see, we have all the words out