Welcome back.
In this video, let's implement a rule to fetch all posts.
So back to the server file here.
Let's close this file and let's open the server file again.
So we're going to create a route to fetch the post.
Lucky for us, we have the skeleton of the route to fetch or post here.
So what we are going to do is that we are going to require this file as postal JSON file and then use
it inside the route.
So let's go ahead and require the post JSON file going to be post equal to required is inside the dot
slash data and we have the JSON file.
So now inside the route to fetch all post here.
Now to be able to send a data in the form of JSON, there is different way of sending data to the client.
Remember, all API responses must retain what is called JSON data.
That is a key and a property name.
So let's make a request to that endpoint or the route.
So here for the list there is no ID, so let's remove that and let's hit send.
You can see that this one is giving me a text, but like I said, API responses must retain a JSON data.
So here you provide what is called JSON welcome here.
So let's save it and now let's get sent.
And now we see that I see something different here to be able to implement this one in Node.js, unless
you do what is called passing the data as chunk and then to buffer and to many steps by way express
with this method, whatever you're passing here would be in a form for JSON.
So now because we have the post data, if you try to console.log the post data here and let's see the
data, we have it.
So let's save it.
And back to the terminal and this is a data we have perfect.
So now instead of just returning this as welcome here inside the fetch post route, we are going to
return the post data.
So save it.
And now back to the postman hit send.
And now we see that I have this and also for JSON method we can pass in additional properties and we
can do so using an object here.
We can provide a message property here message.
And let's say that.
Posts fetched.
Successfully.
So let's save it.
And now back to post.
Let's get signed and see that I have a proper record post first and then the actual post.
It is how we implement the fetch or route.
The next video.
Let's work on how we can fetch a single post, so catch you up the next video.