1
00:00:06,360 --> 00:00:07,590
Welcome back.

2
00:00:07,620 --> 00:00:11,580
In this video, let's go ahead to create some demo route.

3
00:00:11,580 --> 00:00:17,540
And after that, we are going to refactor it to use the MVC design pattern.

4
00:00:17,550 --> 00:00:21,150
So inside the server here are root.

5
00:00:21,150 --> 00:00:28,350
And for this particular application, we are going to have two or three routes based on our model.

6
00:00:28,350 --> 00:00:33,570
So the first one going to be the users root and after users root.

7
00:00:33,570 --> 00:00:41,970
We need the account creation root and after that we need the transaction root.

8
00:00:41,970 --> 00:00:44,490
So here we go.

9
00:00:44,610 --> 00:00:48,510
So for users root, let's have the HTTP method.

10
00:00:48,510 --> 00:00:56,820
The first one going to be the post method and the endpoint going to be API for Slack version one for

11
00:00:56,820 --> 00:00:58,410
Slack users.

12
00:00:58,410 --> 00:00:58,890
All right.

13
00:00:58,890 --> 00:01:00,930
So let's go ahead and create that one.

14
00:01:00,930 --> 00:01:11,940
So going to be app dot posts and then the endpoint going to be as API for slash version one for us slash

15
00:01:11,940 --> 00:01:18,120
users and here goes our callback function and let's make use of async await.

16
00:01:18,120 --> 00:01:22,740
We have our request and then response and I'm going to use a root function.

17
00:01:22,740 --> 00:01:30,060
So here let's bring in, try and catch, let's send some static message to the user by seeing

18
00:01:35,880 --> 00:01:36,720
root.

19
00:01:36,930 --> 00:01:41,040
So the first endpoint here going to be as register.

20
00:01:41,040 --> 00:01:46,020
So here are going to be as register perfect.

21
00:01:46,020 --> 00:01:48,210
So now we got done with the first one.

22
00:01:48,210 --> 00:01:51,450
The second one is going to be the log in.

23
00:01:51,450 --> 00:01:55,260
So I'll copy and change this one to log in.

24
00:01:55,590 --> 00:02:05,520
And the last endpoint here is going to be as log in and here we're going to be as log in root and inside

25
00:02:05,520 --> 00:02:10,139
the catch, let's send the error as error.

26
00:02:10,139 --> 00:02:13,320
So let's copy this one and let's paste it here.

27
00:02:13,320 --> 00:02:16,380
So now we have the two endpoint here.

28
00:02:16,410 --> 00:02:21,030
The next endpoint is going to be the gate or user's endpoint.

29
00:02:21,030 --> 00:02:28,110
But for this particular application, we are going to see all the users unless the admin.

30
00:02:28,110 --> 00:02:34,080
So you can maintain if we want to see all users in your application, you can go ahead and create an

31
00:02:34,080 --> 00:02:35,310
endpoint for that.

32
00:02:35,310 --> 00:02:39,390
So what I want to create right now is going to be the profile.

33
00:02:39,390 --> 00:02:46,410
So here we're going to be as users and then the last endpoint is going to be as pull file.

34
00:02:46,560 --> 00:02:47,190
All right.

35
00:02:47,190 --> 00:02:50,910
So here, let's change this one to profile.

36
00:02:50,940 --> 00:02:53,550
Let's add the dynamic ID here.

37
00:02:53,760 --> 00:03:00,210
So you're going to be asked for a slash ID, so I will show you how we're going to ignore using the

38
00:03:00,210 --> 00:03:01,230
ID by.

39
00:03:01,230 --> 00:03:07,890
Instead, we are going to get the user from the request object and I'll show you as we move on.

40
00:03:07,890 --> 00:03:10,920
So here is going to be as profile.

41
00:03:12,090 --> 00:03:18,030
And after this one, let's go ahead and then create one endpoint.

42
00:03:18,030 --> 00:03:20,160
So here are going to be get request.

43
00:03:20,160 --> 00:03:29,790
Sorry, guys, and for this going to be the delete endpoint so API uses and then we add the ID here

44
00:03:30,510 --> 00:03:32,790
as colon ID.

45
00:03:32,880 --> 00:03:36,390
I forgot to bring the ID here also.

46
00:03:36,720 --> 00:03:37,260
Great.

47
00:03:37,260 --> 00:03:41,790
So now this is going to be as delete endpoint.

48
00:03:41,970 --> 00:03:51,780
So here is going to be forward slash colon ID and you're going to be as delete endpoint or delete root.

49
00:03:51,780 --> 00:03:55,770
And last endpoint you're going to create is for updating.

50
00:03:55,770 --> 00:04:07,590
So you're going to be as put and for updating to we need an ID so users for its last colon ID and here

51
00:04:07,590 --> 00:04:11,280
are going to be as update route.

52
00:04:11,640 --> 00:04:15,990
So the HTTP method here is put endpoint.

53
00:04:15,990 --> 00:04:20,940
So now we have these dummy endpoints for users.

54
00:04:21,120 --> 00:04:23,220
So what about the account?

55
00:04:23,220 --> 00:04:25,110
The process is the same.

56
00:04:25,110 --> 00:04:32,520
This account is a project that we are going to create to keep track of expenses and income for that

57
00:04:32,520 --> 00:04:33,840
particular project.

58
00:04:33,840 --> 00:04:37,710
So here, the endpoint going to be the same thing.

59
00:04:37,860 --> 00:04:44,670
So here are going to be post API users and then here it's going to be as account.

60
00:04:45,210 --> 00:04:51,090
And here, let's change the endpoint from this one to account.

61
00:04:51,930 --> 00:04:52,650
Perfect.

62
00:04:52,650 --> 00:05:00,210
So now when I be asked create account root.

63
00:05:00,330 --> 00:05:03,510
So let's go ahead and then copy this one.

64
00:05:03,720 --> 00:05:05,880
And down here let's paste.

65
00:05:06,200 --> 00:05:08,020
And let's collapse this one.

66
00:05:08,030 --> 00:05:16,730
So here going to be as get a particular account we're going to be as guests and then forward slash column

67
00:05:16,760 --> 00:05:22,880
ID and we're going to be forwards last column ID and you're going to be as.

68
00:05:30,820 --> 00:05:33,610
And for this, the endpoint going to be the same.

69
00:05:33,640 --> 00:05:38,830
But here the HTTP method that differs is going to be as delete.

70
00:05:39,040 --> 00:05:41,710
So here are going to be as delete.

71
00:05:43,210 --> 00:05:48,490
Account root and after deleting you also want to update.

72
00:05:48,490 --> 00:05:56,080
So let me collapse this one and now here are going to be as puts requests for updating it and the same

73
00:05:56,080 --> 00:06:05,590
endpoint we need the ID so here are going to be as put method and the message here is going to be as

74
00:06:06,440 --> 00:06:08,830
an update account root.

75
00:06:09,010 --> 00:06:13,390
So the next endpoint here is going to be the transaction endpoint.

76
00:06:13,390 --> 00:06:22,240
So let's paste that one and the first one going to be post requests and here is going to be transactions,

77
00:06:23,830 --> 00:06:24,310
right?

78
00:06:24,310 --> 00:06:33,760
And then let's remove this one transactions and let's remove the ID and here is going to be as create

79
00:06:36,010 --> 00:06:37,060
transaction.

80
00:06:37,270 --> 00:06:45,970
Then after creating, we also want to fetch all transactions is going to be as gates and then transactions

81
00:06:45,970 --> 00:06:52,990
change this one to get and then here are going to be as get transactions.

82
00:06:52,990 --> 00:07:00,460
So let's copy this one and down here let's pay six and here we want to have a single transaction.

83
00:07:00,460 --> 00:07:08,830
So going to be as colon ID and here is going to be as colon ID and here get transaction single.

84
00:07:09,190 --> 00:07:16,600
And after this one, let's go ahead and then let's also create the delete endpoint.

85
00:07:16,600 --> 00:07:22,450
So here are going to be delete and I would need the same you are or endpoint.

86
00:07:22,450 --> 00:07:30,070
So here I would change this one to delete and they're going to be as delete transaction.

87
00:07:30,370 --> 00:07:43,750
And if you want to update, you will be as put and here is going to be put here going to be as an update

88
00:07:43,750 --> 00:07:44,860
transaction.

89
00:07:45,220 --> 00:07:45,730
All right.

90
00:07:45,730 --> 00:07:52,120
So in case we have some behind the endpoint, we will come back and fix it.

91
00:07:52,360 --> 00:07:57,370
So you can see how our server file is getting clumsy or clustered.

92
00:07:57,370 --> 00:08:02,200
So always the server file responsibility is to start our server.

93
00:08:02,230 --> 00:08:06,460
All the business logic must not be on the server file.

94
00:08:06,550 --> 00:08:14,470
So the next video, let's go ahead and then refactor this particular code to use the routing in experts.

