1
00:00:00,470 --> 00:00:01,500
Not bad, not bad.

2
00:00:01,609 --> 00:00:04,410
I think we're good with the general structure.

3
00:00:04,760 --> 00:00:12,400
So now let's start implementing it and I want to right away set up the router as well as the controllers.

4
00:00:12,830 --> 00:00:19,670
And if you remember, at the very end of the tutorial I covered, why is that necessary and essential?

5
00:00:19,670 --> 00:00:26,240
The short answer is that as our application grows bigger, it's not going to be very sustainable if

6
00:00:26,240 --> 00:00:29,710
we'll just start dumping everything in the trash.

7
00:00:30,110 --> 00:00:33,850
And for the time being, I just want to create this one route.

8
00:00:34,190 --> 00:00:40,730
Now, as far as the response is just going to be a simple string that says, hey, here are all the

9
00:00:40,730 --> 00:00:43,000
items or something along those lines.

10
00:00:43,310 --> 00:00:50,530
And then once we have that one in place, then the rest of them and then we'll test it out in the postman.

11
00:00:51,230 --> 00:00:52,250
So let's get cracking.

12
00:00:52,670 --> 00:00:54,460
And I'm going to go with new folder.

13
00:00:54,510 --> 00:00:58,020
So here will be all the controllers.

14
00:00:58,040 --> 00:01:00,650
And in this case, I'm going to be looking for tasks.

15
00:01:01,010 --> 00:01:04,400
And I also want to set up a root folder.

16
00:01:04,819 --> 00:01:10,070
So in the root folder, we'll go with new file and same thing.

17
00:01:10,280 --> 00:01:12,720
We're going to go with tasks, Jay.

18
00:01:13,760 --> 00:01:21,600
And then as far as the setup in The Roots, we need to look for the express router, so say Const Express,

19
00:01:21,860 --> 00:01:23,560
and that is equal to require.

20
00:01:23,960 --> 00:01:25,580
And then again, we'll look for Xpress.

21
00:01:25,760 --> 00:01:31,270
And there should be a refresher because we did cover that at the end of the express tutorial.

22
00:01:31,700 --> 00:01:38,470
So just to jog your memory, if we go back to express tutorial and more specifically, we'll look for

23
00:01:38,470 --> 00:01:45,560
the final one, the 513, the router people chose a basic router example.

24
00:01:45,950 --> 00:01:48,140
And essentially we have two options.

25
00:01:48,530 --> 00:01:56,120
We can either go with Aurora, get and then add all the controllers one by one, or we can actually

26
00:01:56,120 --> 00:01:59,900
churn them together where we go with a router and then use a route.

27
00:02:00,230 --> 00:02:07,220
So this is going to be the main route in our case, API version one and then task and then we train,

28
00:02:07,460 --> 00:02:09,169
get and post.

29
00:02:09,380 --> 00:02:11,620
And I think I'm going to go with this setup.

30
00:02:11,950 --> 00:02:17,870
So first, let's start by setting up the router and that is equal to express and then router.

31
00:02:17,870 --> 00:02:22,240
We invoke it and then eventually we'll import controllers.

32
00:02:22,370 --> 00:02:24,160
But for now, of course, we don't have any.

33
00:02:24,440 --> 00:02:32,240
So let's just leave that one blank and we'll go with router router then route, like I said, then forward

34
00:02:32,240 --> 00:02:35,000
slash and then I want to go with that method.

35
00:02:35,360 --> 00:02:39,590
And for the time being, I'll just hard code the response over here.

36
00:02:39,890 --> 00:02:45,860
So say Iraq and rise and rise, dot and send.

37
00:02:46,080 --> 00:02:50,470
And like I said, we'll just start simply so say all items.

38
00:02:50,960 --> 00:02:58,430
Now let's say that one and then all the way in the bottom, we want to go with module exports and that

39
00:02:58,430 --> 00:03:00,170
is equal to our router.

40
00:03:00,470 --> 00:03:07,400
So now back in the U.S., we want to import the router, we want to import our tasks and we want to

41
00:03:07,400 --> 00:03:08,660
set up of the middleware.

42
00:03:09,110 --> 00:03:13,010
So on here, let's just go with CONSED and then route.

43
00:03:13,010 --> 00:03:15,380
And that is equal to require.

44
00:03:15,740 --> 00:03:22,580
And then like I said, we're going to be looking in the wrong folder and more specifically, we're looking

45
00:03:22,580 --> 00:03:23,600
for tasks.

46
00:03:24,050 --> 00:03:25,240
And then right after this.

47
00:03:25,250 --> 00:03:25,640
Hello.

48
00:03:25,940 --> 00:03:28,370
And don't worry, we'll change that one a little bit later.

49
00:03:28,370 --> 00:03:30,890
For the time being, it can just stay the way it is.

50
00:03:31,160 --> 00:03:38,660
We'll go with Abduh use and then, of course, what we're looking for, well, we want to go with API

51
00:03:39,170 --> 00:03:41,510
and version one and then tasks.

52
00:03:41,930 --> 00:03:45,710
That's going to be the root root for these tasks, rather.

53
00:03:46,010 --> 00:03:51,800
And then we just want to go with our roots and not let's just change that on my board.

54
00:03:51,890 --> 00:03:53,330
For some reason I went with the Roots.

55
00:03:53,810 --> 00:03:55,520
Let's just call it tasks.

56
00:03:55,940 --> 00:03:58,430
I believe it's going to make a bit more sense.

57
00:03:58,640 --> 00:04:05,300
And since we'll be sending JSON from our application, for example, when we're creating a new task,

58
00:04:05,660 --> 00:04:12,770
and since I want to access that data in my roots, what do we need to do, of course, is get middleware

59
00:04:12,770 --> 00:04:17,810
that is built into express and not middleware is express JSON.

60
00:04:18,110 --> 00:04:25,730
So above the roots will go here and I'll try to spell this correctly, since that is always an issue.

61
00:04:26,150 --> 00:04:32,030
Hopefully this is correct middleware and then we'll just go with that use and eventually it will set

62
00:04:32,030 --> 00:04:33,200
up the static one as well.

63
00:04:34,010 --> 00:04:40,160
But since at the moment we have barely any roots, I'm just going to go with Express Andreessen.

64
00:04:40,490 --> 00:04:47,230
If you remember, if we don't use this, then we won't have that data in Iraq dogsbody.

65
00:04:47,600 --> 00:04:52,970
So we'll save it here and I'll leave the comments just so we all are on the same page.

66
00:04:53,360 --> 00:04:56,630
And before I tested out in the browser, let me just double check.

67
00:04:56,990 --> 00:04:59,720
So I'm using the middleware where?

68
00:04:59,810 --> 00:05:07,370
I'm saying that I'm looking for API version one and then tasks, and then I pass in my router, my tasks

69
00:05:07,370 --> 00:05:15,650
are and then in the router effectively I have this growth path which just matches whatever I pass over

70
00:05:15,650 --> 00:05:15,950
here.

71
00:05:16,280 --> 00:05:24,170
So again, I go with API version one and then tasks, and then I set up a GETRUDE where I manually pass

72
00:05:24,210 --> 00:05:28,450
in my controller and here I just say, is that sand?

73
00:05:28,630 --> 00:05:33,560
And I pass in a string of items and looks about right.

74
00:05:34,010 --> 00:05:41,030
So let me go here and we're going to go with localhost three thousand six is a get request because we

75
00:05:41,030 --> 00:05:49,610
can access it then API version one and then tasks and we should see a string of items.

76
00:05:49,880 --> 00:05:53,660
And if we do, then of course we're heading in the right direction.

77
00:05:53,930 --> 00:06:00,320
So the last thing that I want to do in this video is the first close my express tutorial one.

78
00:06:00,740 --> 00:06:06,590
And then in the controllers, we want to create a new file and we'll call these tasks JS.

79
00:06:06,980 --> 00:06:13,040
And again, just to jog your memory, the whole deal, why we're setting up separate routes and separate

80
00:06:13,040 --> 00:06:21,400
controllers, because if I'll try to jump everything in, just it's going to get messy pretty fast.

81
00:06:21,710 --> 00:06:28,100
So what I want to do right now is take this logic and place it in a separate file, because eventually,

82
00:06:28,100 --> 00:06:31,920
of course, there will be way more logic than just Araz dots.

83
00:06:31,990 --> 00:06:38,630
And so we're going to go to my controllers and effectively, I want to create my function of the controller

84
00:06:38,630 --> 00:06:47,030
function and I'm just going to go with const get all and then tasks and I'll set it up as an R function.

85
00:06:47,300 --> 00:06:54,680
I'm looking for Iraq and RES and functionality will be exactly the same, whereas not sand and we're

86
00:06:54,680 --> 00:07:00,920
just going to go it all and learn items and then we're going to go with module exports.

87
00:07:01,130 --> 00:07:06,710
And since I'm going to add more functions in here, I'll right away explore it as an object.

88
00:07:07,010 --> 00:07:08,990
So I get all tasks.

89
00:07:09,070 --> 00:07:10,310
That's when I'm exporting.

90
00:07:10,490 --> 00:07:13,880
And then back in the Roots course, I want to access it.

91
00:07:14,150 --> 00:07:21,080
It's also here that I wanted the structure get tasks from and of course we need to require it.

92
00:07:21,410 --> 00:07:25,520
And in this case, we're looking in the controllers.

93
00:07:25,790 --> 00:07:27,590
So I'm going to go two levels up.

94
00:07:27,590 --> 00:07:30,680
I'm looking for controllers and then a more specific task.

95
00:07:30,980 --> 00:07:37,790
So instead of hard coding this value, of course I'll just pass it in and I'll say get all tasks.

96
00:07:38,150 --> 00:07:46,080
And if I go back to my YORO, if I can still see all items, then of course we are in good shape.

97
00:07:46,190 --> 00:07:52,670
And let me just set out where I'll change this around and I'll say all items from.

98
00:07:53,500 --> 00:07:54,850
From the file.

99
00:07:56,380 --> 00:08:03,070
And if we go back, yep, we still have the correct result, and with this in place now, we can set

100
00:08:03,070 --> 00:08:07,270
up the same basic structure for the rest of the routes as well.

