1
00:00:04,510 --> 00:00:08,650
Let's get started with express routing.

2
00:00:09,010 --> 00:00:15,640
Well, before we get into this, let's look at the final project that we are going to build.

3
00:00:16,120 --> 00:00:26,560
We are going to build a simple API where we can perform all the operations like delete, create, update

4
00:00:26,560 --> 00:00:28,950
and fetch a single record.

5
00:00:28,960 --> 00:00:36,970
And we are not going to use any database yet, but instead we are going to use the FS module from Node.js

6
00:00:36,970 --> 00:00:39,640
to write the data onto a file.

7
00:00:39,820 --> 00:00:46,290
And I will also show you a tool called Postman for API Development.

8
00:00:46,300 --> 00:00:50,380
So let's get back to the project and see how it's going to work.

9
00:00:50,590 --> 00:00:58,930
The cool thing about this application is that as soon as I run the server, it is going to create a

10
00:00:58,930 --> 00:01:05,780
folder called Data where we have a file called post dot JSON file.

11
00:01:05,800 --> 00:01:11,740
So let's run the server and see if it's going to create those folders and files.

12
00:01:11,860 --> 00:01:13,630
So put your eyes here.

13
00:01:13,630 --> 00:01:19,390
As soon as the server get connected, you can see that it's going to generate a folder for me.

14
00:01:19,420 --> 00:01:21,010
Moment of truth.

15
00:01:21,010 --> 00:01:31,240
And indeed we have a folder called Data and inside it has generated a file called post dot json file.

16
00:01:31,270 --> 00:01:39,250
And on that it has written a content or a sample post onto the file how awesome it is.

17
00:01:39,250 --> 00:01:42,520
And you are going to create the function to get this done.

18
00:01:42,520 --> 00:01:45,880
And that function is inside the utils file.

19
00:01:46,030 --> 00:01:49,690
So now we have a data where we can work on.

20
00:01:49,690 --> 00:01:57,670
So on this file we can add a new post onto this file or we can fetch a single record on this file or

21
00:01:57,670 --> 00:02:00,730
we can delete a file and it will reflect.

22
00:02:00,730 --> 00:02:03,100
So let's see how it's going to work.

23
00:02:03,280 --> 00:02:05,470
Now back to my server file here.

24
00:02:05,470 --> 00:02:07,540
Let me use the file that I created.

25
00:02:07,750 --> 00:02:09,610
That is the JSON file.

26
00:02:09,970 --> 00:02:11,680
So back to Postman.

27
00:02:11,680 --> 00:02:17,880
What I'm going to do is that I'm going to fetch all the posts inside the JSON file.

28
00:02:17,890 --> 00:02:19,840
So now moment of truth.

29
00:02:19,960 --> 00:02:27,910
When I hit send it will see that the post that the server created and this is what I see here, check

30
00:02:27,910 --> 00:02:28,360
it out.

31
00:02:28,360 --> 00:02:31,000
And indeed this is what we have.

32
00:02:31,300 --> 00:02:35,600
So what about if we want to add a record or post onto the file?

33
00:02:35,620 --> 00:02:36,480
Now let's see.

34
00:02:36,490 --> 00:02:43,180
And you are going to use what is called create and you are going to use HTTP method called post.

35
00:02:43,300 --> 00:02:46,450
So now when I hit send, now have a look.

36
00:02:46,460 --> 00:02:50,410
It will see that I get very full message that post created.

37
00:02:50,440 --> 00:02:52,760
Now let's check it out on the file.

38
00:02:52,780 --> 00:02:56,740
Indeed, I have a new post onto the file.

39
00:02:56,770 --> 00:03:01,960
How awesome it is and I can go ahead and create new post this time around.

40
00:03:01,960 --> 00:03:06,190
Let me see how to learn CSS like that and then this.

41
00:03:06,190 --> 00:03:13,000
I'm going to be the you are going to be something like two and four description, let's say the best

42
00:03:13,000 --> 00:03:15,690
post ever to when I hit send.

43
00:03:15,700 --> 00:03:17,560
Now have a look on the file.

44
00:03:17,770 --> 00:03:18,640
Have a look.

45
00:03:18,670 --> 00:03:24,790
It could say that indeed we have it and has given me the ID automatically.

46
00:03:24,790 --> 00:03:25,570
You can see.

47
00:03:25,570 --> 00:03:33,580
And it's even added a new post on top of it because I use on shift meaning for on shift it adds a new

48
00:03:33,580 --> 00:03:35,440
content onto the array.

49
00:03:35,680 --> 00:03:40,660
So what about if you are trying to delete a post or a record?

50
00:03:40,750 --> 00:03:44,110
Right now you have three real code 1 to 3.

51
00:03:44,110 --> 00:03:49,150
So let's say I want delete the one wait id 202.

52
00:03:49,300 --> 00:03:53,230
So now the end point or the root is going to be delete.

53
00:03:53,230 --> 00:03:56,080
So I provide to zero two.

54
00:03:56,110 --> 00:03:59,590
Now when I hit st indeed I have a message.

55
00:03:59,740 --> 00:04:02,590
Is that post deleted successfully?

56
00:04:02,830 --> 00:04:08,620
And you can see that we have two files now I can go ahead and then delete the rest.

57
00:04:08,620 --> 00:04:13,660
Let's say I want to provide the ID of two and or one.

58
00:04:13,690 --> 00:04:18,220
Let me say to let me hit send and you can see that post has been deleted.

59
00:04:18,220 --> 00:04:24,690
So let me create more post here and let's check the file and you can see that now I have two files,

60
00:04:24,700 --> 00:04:25,150
whatever.

61
00:04:25,150 --> 00:04:28,900
If I want to fetch a single record, I'm going to use this endpoint.

62
00:04:28,900 --> 00:04:33,160
So now I want to find a post with ID of one.

63
00:04:33,160 --> 00:04:35,440
It means I'm going to retrieve this post.

64
00:04:35,440 --> 00:04:36,550
So now have a look.

65
00:04:36,610 --> 00:04:39,490
And you can see that this is a post I have.

66
00:04:39,490 --> 00:04:46,690
What about if I want to update the same process I provide ID and let's say that this was going to be,

67
00:04:46,720 --> 00:04:52,630
let me say, updated the title only hit send and now have a look.

68
00:04:52,630 --> 00:04:57,010
And indeed I have one post being updated with a title of this.

69
00:04:57,010 --> 00:04:59,920
I can go ahead and update the description.

70
00:04:59,920 --> 00:05:01,600
Also, I will say that.

71
00:05:01,990 --> 00:05:03,910
Great as that.

72
00:05:04,310 --> 00:05:07,700
So let me hit send and now let's check it out.

73
00:05:07,700 --> 00:05:10,940
And indeed it has been updated, guys.

74
00:05:10,940 --> 00:05:12,860
So this is awesome project.

