Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,050 --> 00:00:02,090
Welcome back.
2
00:00:02,090 --> 00:00:04,653
In this video, let's start to implement some routes
3
00:00:04,653 --> 00:00:07,023
for the users' resource.
4
00:00:08,460 --> 00:00:12,110
So, our A-P-I will have a couple of different resources.
5
00:00:12,110 --> 00:00:14,080
The first one that we already talked about
6
00:00:14,080 --> 00:00:17,490
and started to implement is the tours resource.
7
00:00:17,490 --> 00:00:20,240
But another one will be the users' resource.
8
00:00:20,240 --> 00:00:22,900
So that, for example, we can create user accounts
9
00:00:22,900 --> 00:00:24,680
and have different user roles
10
00:00:24,680 --> 00:00:28,003
and all that good stuff that comes with users, right?
11
00:00:28,850 --> 00:00:32,030
Now, of course, for now, this users' resource
12
00:00:32,030 --> 00:00:34,720
will be very similar to the tours resource.
13
00:00:34,720 --> 00:00:37,970
But I still want to start implementing this resource
14
00:00:37,970 --> 00:00:40,240
at this point because we need to move forward
15
00:00:40,240 --> 00:00:42,990
in the project and also because I need it
16
00:00:42,990 --> 00:00:47,460
in order to prepare for what I'm gonna teach you next, okay?
17
00:00:47,460 --> 00:00:52,300
So let's go ahead and move down here to our route,
18
00:00:52,300 --> 00:00:55,290
and so what we'll do again, something very similar,
19
00:00:55,290 --> 00:00:57,016
to what we already have here.
20
00:00:57,016 --> 00:01:00,519
(keyboard clicking)
21
00:01:00,519 --> 00:01:02,160
So app.route,
22
00:01:02,160 --> 00:01:05,521
and route is gonna be slash A-P-I,
23
00:01:05,521 --> 00:01:07,073
slash version one,
24
00:01:08,090 --> 00:01:09,410
and then users'.
25
00:01:09,410 --> 00:01:13,590
Okay, and then we will respond to the get request
26
00:01:13,590 --> 00:01:17,140
using a function, then we're going to create next called get
27
00:01:18,450 --> 00:01:19,940
all users.
28
00:01:19,940 --> 00:01:21,970
So you see that the structure that I'm gonna follow
29
00:01:21,970 --> 00:01:24,810
is very similar to the one with tours.
30
00:01:24,810 --> 00:01:28,710
So, when we do get or post on the route without the ID,
31
00:01:28,710 --> 00:01:31,440
so, just like this or just like this,
32
00:01:31,440 --> 00:01:34,640
it means that we either want to get all the users,
33
00:01:34,640 --> 00:01:37,100
so basically, all the objects that are part of
34
00:01:37,100 --> 00:01:40,130
a resource, and if we use post, then we want to create
35
00:01:40,130 --> 00:01:43,550
a new resource on a server, okay?
36
00:01:43,550 --> 00:01:46,153
So, that pattern is always gonna be the same.
37
00:01:49,110 --> 00:01:51,740
So, create user for now.
38
00:01:51,740 --> 00:01:53,630
And, so, now it's giving me an error because
39
00:01:53,630 --> 00:01:55,460
all these functions are not defined,
40
00:01:55,460 --> 00:01:57,634
but don't worry about that.
41
00:01:57,634 --> 00:02:00,810
(keyboard clicking)
42
00:02:00,810 --> 00:02:03,120
So, A-P-I, actually, slash,
43
00:02:03,120 --> 00:02:05,363
so we always need to start with a slash.
44
00:02:07,510 --> 00:02:10,699
Users, and then just like before,
45
00:02:10,699 --> 00:02:14,730
we have to use this ID as a parameter interrupt.
46
00:02:14,730 --> 00:02:19,040
Okay, then, if we do get request specifying that ID,
47
00:02:19,040 --> 00:02:21,950
it means that we want to get one user.
48
00:02:21,950 --> 00:02:25,450
So, I'm just calling it get user.
49
00:02:25,450 --> 00:02:26,283
Okay?
50
00:02:26,283 --> 00:02:28,540
And there are different kind of standards here,
51
00:02:28,540 --> 00:02:30,920
so you could call this one, here, get one user,
52
00:02:30,920 --> 00:02:32,050
and this one here get all users,
53
00:02:32,050 --> 00:02:35,770
but I prefer to just do it like this, all right?
54
00:02:35,770 --> 00:02:39,233
So, we also want to respond to the patch request.
55
00:02:40,610 --> 00:02:41,993
So, update user,
56
00:02:43,110 --> 00:02:45,333
and then also delete.
57
00:02:46,400 --> 00:02:50,130
And this one is gonna be called delete user.
58
00:02:50,130 --> 00:02:55,130
Give it a save, and, so it nicely formats our code, here.
59
00:02:55,330 --> 00:02:56,190
And, so, let's go ahead
60
00:02:56,190 --> 00:02:58,900
and quickly create these five functions.
61
00:02:58,900 --> 00:03:01,020
And we're gonna do that all right away,
62
00:03:01,020 --> 00:03:02,700
because we will actually not
63
00:03:02,700 --> 00:03:05,500
do anything for the users at this point.
64
00:03:05,500 --> 00:03:07,980
Okay, again I just wanted to have this implemented
65
00:03:07,980 --> 00:03:10,510
in order to show you something next.
66
00:03:10,510 --> 00:03:13,363
Okay, so, I'm going to go ahead, copy this one here.
67
00:03:14,780 --> 00:03:18,110
And, yeah, so, add a tier right after
68
00:03:18,110 --> 00:03:20,010
the last route handler from the tours.
69
00:03:22,870 --> 00:03:24,693
So, const get all users.
70
00:03:25,674 --> 00:03:29,330
(keyboard clicking)
71
00:03:29,330 --> 00:03:32,160
And what I will do here is to simply send back a message
72
00:03:32,160 --> 00:03:34,780
that this route is not yet implemented.
73
00:03:34,780 --> 00:03:38,290
So, response to status that I'm going to specify as 500,
74
00:03:38,290 --> 00:03:41,100
which means internal server error, and
75
00:03:42,780 --> 00:03:46,560
so, yeah, for now that's just kind of a place holder,
76
00:03:46,560 --> 00:03:51,050
so we still send back a adjacent object with a status,
77
00:03:51,050 --> 00:03:54,900
which in this case, when there is a 500 error code
78
00:03:54,900 --> 00:03:57,170
we say that it's an error, okay?
79
00:03:57,170 --> 00:03:59,913
So, what was that weird error completion,
80
00:04:00,860 --> 00:04:04,697
we simply only want error, and then message:
81
00:04:04,697 --> 00:04:08,167
(keyboard clicking)
82
00:04:08,167 --> 00:04:11,310
this route is not yet defined.
83
00:04:11,310 --> 00:04:14,720
All right, give this a save,
84
00:04:14,720 --> 00:04:17,019
and I'm going to go ahead and copy this a couple of times,
85
00:04:17,019 --> 00:04:19,762
and simply do the same for all the other ones.
86
00:04:22,720 --> 00:04:27,633
Okay, so, get all users, then get user,
87
00:04:28,470 --> 00:04:31,963
then I want create user,
88
00:04:34,640 --> 00:04:36,370
I want to update user
89
00:04:38,570 --> 00:04:41,470
and delete, oh where is that?
90
00:04:41,470 --> 00:04:42,653
It's nowhere here.
91
00:04:44,280 --> 00:04:46,300
Delete user.
92
00:04:46,300 --> 00:04:47,360
Okay.
93
00:04:47,360 --> 00:04:49,980
So now, there's no more error and
94
00:04:50,980 --> 00:04:53,050
let's get rid of this piece of code.
95
00:04:53,050 --> 00:04:56,180
And, so, if we now create a request for this
96
00:04:56,180 --> 00:04:57,330
let's see what happens.
97
00:04:59,750 --> 00:05:02,683
And close this one, copy this one.
98
00:05:06,766 --> 00:05:08,566
And, oh yeah, of course.
99
00:05:08,566 --> 00:05:12,566
So, I needed to change this to users, obviously.
100
00:05:13,980 --> 00:05:17,260
And so now we have our 500 internal server error here,
101
00:05:17,260 --> 00:05:19,210
and then this route is not yet defined.
102
00:05:20,050 --> 00:05:22,880
Let's still go ahead and save this request
103
00:05:23,800 --> 00:05:25,410
into a new collection.
104
00:05:25,410 --> 00:05:27,430
Actually, we want it in the same collection,
105
00:05:27,430 --> 00:05:28,643
just another folder.
106
00:05:29,640 --> 00:05:31,453
So let's create a folder later.
107
00:05:32,460 --> 00:05:35,950
So we get all users.
108
00:05:35,950 --> 00:05:36,880
Save it here.
109
00:05:36,880 --> 00:05:39,720
And now we can go ahead and create a folder,
110
00:05:39,720 --> 00:05:41,940
and not like this, but this.
111
00:05:41,940 --> 00:05:46,700
So, add folder, and so let's add one folder
112
00:05:46,700 --> 00:05:48,270
for each of the resource.
113
00:05:48,270 --> 00:05:49,233
So we have tour,
114
00:05:51,232 --> 00:05:53,290
and we have users.
115
00:05:53,290 --> 00:05:56,367
So it's gonna called just like the--
116
00:05:57,320 --> 00:05:58,220
like the resource.
117
00:05:59,320 --> 00:06:03,083
All right, for some reason I cannot select all of them.
118
00:06:04,800 --> 00:06:06,033
That's no problem.
119
00:06:11,930 --> 00:06:14,700
All right, so now we have them nicely organized here
120
00:06:14,700 --> 00:06:17,910
in our collection, and that's a lot nicer.
121
00:06:17,910 --> 00:06:20,680
All right, so that is how we define code
122
00:06:20,680 --> 00:06:23,200
for our second resource.
123
00:06:23,200 --> 00:06:25,980
All right, so this file is kind of a mess,
124
00:06:25,980 --> 00:06:28,360
so, we have all of this mixed-up together in the same file,
125
00:06:28,360 --> 00:06:31,564
all these routes, all these handlers, here,
126
00:06:31,564 --> 00:06:34,253
which we can also call controllers, by the way.
127
00:06:36,460 --> 00:06:40,230
Okay, and so we have all these different pieces in the same
128
00:06:40,230 --> 00:06:44,110
file and eventually we will want to fix that.
129
00:06:44,110 --> 00:06:47,280
So, in the next video, we're gonna take the first step in
130
00:06:47,280 --> 00:06:50,190
order to be able to actually separate all these different
131
00:06:50,190 --> 00:06:52,133
pieces into different files.
10012
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.