1
00:00:04,240 --> 00:00:05,590
Welcome back.

2
00:00:05,680 --> 00:00:10,120
In this video, let's implement a rule to fetch all posts.

3
00:00:10,240 --> 00:00:12,790
So back to the server file here.

4
00:00:12,820 --> 00:00:17,050
Let's close this file and let's open the server file again.

5
00:00:17,320 --> 00:00:20,560
So we're going to create a route to fetch the post.

6
00:00:20,860 --> 00:00:25,750
Lucky for us, we have the skeleton of the route to fetch or post here.

7
00:00:26,050 --> 00:00:34,660
So what we are going to do is that we are going to require this file as postal JSON file and then use

8
00:00:34,660 --> 00:00:35,980
it inside the route.

9
00:00:36,250 --> 00:00:46,870
So let's go ahead and require the post JSON file going to be post equal to required is inside the dot

10
00:00:46,870 --> 00:00:50,740
slash data and we have the JSON file.

11
00:00:51,010 --> 00:00:54,550
So now inside the route to fetch all post here.

12
00:00:54,580 --> 00:01:02,500
Now to be able to send a data in the form of JSON, there is different way of sending data to the client.

13
00:01:02,560 --> 00:01:09,700
Remember, all API responses must retain what is called JSON data.

14
00:01:09,700 --> 00:01:12,190
That is a key and a property name.

15
00:01:12,610 --> 00:01:16,030
So let's make a request to that endpoint or the route.

16
00:01:16,030 --> 00:01:21,310
So here for the list there is no ID, so let's remove that and let's hit send.

17
00:01:21,340 --> 00:01:30,220
You can see that this one is giving me a text, but like I said, API responses must retain a JSON data.

18
00:01:30,220 --> 00:01:33,880
So here you provide what is called JSON welcome here.

19
00:01:33,910 --> 00:01:37,090
So let's save it and now let's get sent.

20
00:01:37,090 --> 00:01:44,680
And now we see that I see something different here to be able to implement this one in Node.js, unless

21
00:01:44,680 --> 00:01:51,640
you do what is called passing the data as chunk and then to buffer and to many steps by way express

22
00:01:51,640 --> 00:01:56,980
with this method, whatever you're passing here would be in a form for JSON.

23
00:01:56,980 --> 00:02:05,800
So now because we have the post data, if you try to console.log the post data here and let's see the

24
00:02:05,800 --> 00:02:07,000
data, we have it.

25
00:02:07,000 --> 00:02:07,930
So let's save it.

26
00:02:07,930 --> 00:02:13,030
And back to the terminal and this is a data we have perfect.

27
00:02:13,150 --> 00:02:20,620
So now instead of just returning this as welcome here inside the fetch post route, we are going to

28
00:02:20,620 --> 00:02:23,260
return the post data.

29
00:02:23,290 --> 00:02:24,250
So save it.

30
00:02:24,250 --> 00:02:26,740
And now back to the postman hit send.

31
00:02:26,740 --> 00:02:36,190
And now we see that I have this and also for JSON method we can pass in additional properties and we

32
00:02:36,190 --> 00:02:39,010
can do so using an object here.

33
00:02:39,010 --> 00:02:43,870
We can provide a message property here message.

34
00:02:45,220 --> 00:02:46,960
And let's say that.

35
00:02:47,660 --> 00:02:50,000
Posts fetched.

36
00:02:51,900 --> 00:02:53,520
Successfully.

37
00:02:53,700 --> 00:02:54,720
So let's save it.

38
00:02:54,720 --> 00:02:55,740
And now back to post.

39
00:02:56,070 --> 00:03:01,870
Let's get signed and see that I have a proper record post first and then the actual post.

40
00:03:01,900 --> 00:03:06,390
It is how we implement the fetch or route.

41
00:03:06,510 --> 00:03:07,500
The next video.

42
00:03:07,500 --> 00:03:13,320
Let's work on how we can fetch a single post, so catch you up the next video.

