1
00:00:04,590 --> 00:00:05,820
Welcome back.

2
00:00:05,850 --> 00:00:09,780
Let's get started with press routing.

3
00:00:09,810 --> 00:00:11,580
So what is it?

4
00:00:11,850 --> 00:00:22,440
Well, it refers to determine how an application responds to a client's request for a specific endpoint,

5
00:00:22,440 --> 00:00:32,400
which is a URL or path and a specific HTTP request method that is Gates, post, delete, and so on

6
00:00:32,400 --> 00:00:33,600
and so on.

7
00:00:33,870 --> 00:00:43,260
So routing simply means how a user can get a response after the person has made a request, or in short,

8
00:00:43,290 --> 00:00:46,080
is a way of getting a resource.

9
00:00:46,200 --> 00:00:54,090
So from the previous video about demonstrating this application, you can see that when I want to fetch

10
00:00:54,090 --> 00:01:02,490
or post, I provide what is called the route, and this route comprises of the HTTP method and then

11
00:01:02,490 --> 00:01:03,350
the you are.

12
00:01:03,510 --> 00:01:10,530
So when I send the help of the routes, I'm able to get the resources that I'm requesting for.

13
00:01:10,560 --> 00:01:15,900
So now let's dive in more to talk about what is called the HTTP method.

14
00:01:16,200 --> 00:01:22,620
The technical term here or the key term here is what you call the HTTP method.

15
00:01:22,620 --> 00:01:25,230
What is HTTP method?

16
00:01:25,470 --> 00:01:31,710
At HTTP methods are the actions that can be performed on a resource.

17
00:01:31,950 --> 00:01:40,950
The most common HTTP methods are gates, post, put, patch and delete, and that is what we have specified

18
00:01:40,950 --> 00:01:41,520
here.

19
00:01:41,640 --> 00:01:44,940
So it's an action of getting a resource.

20
00:01:44,940 --> 00:01:46,800
What action do you want to take?

21
00:01:46,830 --> 00:01:53,330
Do you want to delete a record or a resource or do you want to create or do you want to update or do

22
00:01:53,340 --> 00:01:54,330
you want to delete?

23
00:01:54,330 --> 00:01:57,030
This is what you call an action.

24
00:01:57,210 --> 00:02:03,480
So the action that you take determined by the HTTP method.

25
00:02:03,690 --> 00:02:09,240
Now let's have a look at the component of a route.

26
00:02:09,330 --> 00:02:15,510
A route is made up of what first is we have what is called the main you are URL.

27
00:02:15,690 --> 00:02:18,210
So back to the project here.

28
00:02:18,240 --> 00:02:24,720
Looking at this one, the main you are URL is from here up to here.

29
00:02:25,110 --> 00:02:29,820
Anything after for slash is what we call a resource.

30
00:02:29,820 --> 00:02:37,920
So for this, let's assume that we have developed application and in light production we have the URL.

31
00:02:37,920 --> 00:02:41,460
So this is what we call the main you are URL.

32
00:02:41,820 --> 00:02:50,220
Now for this application, there must be a lot of resources, let's say post or courses or users or

33
00:02:50,220 --> 00:02:50,880
comments.

34
00:02:50,880 --> 00:02:55,800
So what kind of resource do you want to fetch or do you want to play around with it?

35
00:02:55,950 --> 00:03:02,280
So let's say that in your case you are going to play around or fetch all posts and this is what you

36
00:03:02,280 --> 00:03:03,930
call resources.

37
00:03:03,930 --> 00:03:05,400
So back to this one.

38
00:03:05,400 --> 00:03:10,560
If we see that we have the menu URL and then forward slash.

39
00:03:10,590 --> 00:03:11,100
All right.

40
00:03:11,100 --> 00:03:14,460
And then this what you call the resources.

41
00:03:14,460 --> 00:03:22,170
So when I remove the resources here and I say you can see that I guess something strange here, meaning

42
00:03:22,170 --> 00:03:25,650
that there is no resources matching this route.

43
00:03:25,950 --> 00:03:30,390
So if I provide, let's say one, it means that I'm fetching one.

44
00:03:30,390 --> 00:03:33,390
And in that case there is no route handling this.

45
00:03:33,390 --> 00:03:37,170
So if I make a search, definitely I get an error.

46
00:03:37,170 --> 00:03:43,830
But if I provide post is a resource and when I make the request I get the resource.

47
00:03:43,830 --> 00:03:48,660
So anything after for Slash is what you call a resource.

48
00:03:49,080 --> 00:03:56,850
And the action that you want to take is what we call get because that means that getting something from

49
00:03:56,850 --> 00:04:01,380
the server and this is what we call the HTTP method.

50
00:04:01,530 --> 00:04:09,750
So the combination of the HTTP method menu are URL and the resource make up what is called the root

51
00:04:09,930 --> 00:04:11,370
or endpoint.

52
00:04:11,370 --> 00:04:15,360
So if you hear me saying root, I'm referring to endpoint.

53
00:04:15,360 --> 00:04:22,320
In layman's understanding of endpoints, we often say you are URL, but as a programmer we need to speak

54
00:04:22,320 --> 00:04:24,360
programming technical terms.

55
00:04:24,450 --> 00:04:24,990
All right.

56
00:04:24,990 --> 00:04:29,580
So now let's explain more about the HTTP methods.

57
00:04:29,700 --> 00:04:36,750
So let's say that we have developed an application where we create post, fake post and delete all posts.

58
00:04:36,750 --> 00:04:41,250
Let's look at the root with it respective HTTP method.

59
00:04:41,370 --> 00:04:47,220
So for this one, let's say that for this application that we build, it is about posts.

60
00:04:47,220 --> 00:04:54,570
So this is what we call the resources to fetch all posts and we have a method called get meaning.

61
00:04:54,570 --> 00:05:00,240
Fetching means that we need to use what get request or get a HTTP method.

62
00:05:00,420 --> 00:05:03,810
So what about if I want to fetch a single record?

63
00:05:04,370 --> 00:05:08,510
Looking for a single look at the root here the menu.

64
00:05:08,510 --> 00:05:12,410
Ah, plus resources and then plus an ID.

65
00:05:12,440 --> 00:05:18,800
So looking at this route here, there are differences between the first one and the second one.

66
00:05:18,830 --> 00:05:25,970
They all start from where the main you are arrow and then to this end point here.

67
00:05:26,240 --> 00:05:33,500
Now this one is a resource and after that we have a slide with semicolon here.

68
00:05:33,530 --> 00:05:41,830
And this is also a resource because it also comes after four slash, but instead we have colon here,

69
00:05:41,840 --> 00:05:43,370
then we added ID.

70
00:05:43,400 --> 00:05:46,490
So this is what you call params, right?

71
00:05:46,490 --> 00:05:50,750
Because we don't know what kind of posts a user is trying to face.

72
00:05:50,750 --> 00:05:53,060
So the ID might be dynamic.

73
00:05:53,060 --> 00:05:58,430
So anything after colon like this is what we call params.

74
00:05:58,430 --> 00:06:06,950
So for this one, the params here is one because for this one it matches the exact route here.

75
00:06:07,310 --> 00:06:12,080
So for this one too, we are going to use what is called gate request.

76
00:06:12,080 --> 00:06:18,920
So what about if you want to create, look here for create, you provided a post request and then the

77
00:06:18,920 --> 00:06:19,460
route.

78
00:06:19,460 --> 00:06:25,910
So when I hit send with the post, it means that I'm able to create a resource and save it onto the

79
00:06:25,910 --> 00:06:30,140
server and we use what is called post HTTP method.

80
00:06:30,350 --> 00:06:37,400
Then what about if I want to update, we are going to use HTTP method called put.

81
00:06:37,400 --> 00:06:46,040
So looking at this route here for PWD and then forget a single record or post, we see that they follow

82
00:06:46,070 --> 00:06:49,310
the same route with the post with some ID.

83
00:06:49,340 --> 00:06:54,920
So these two routes are different because of the HTTP method.

84
00:06:54,920 --> 00:06:57,890
So these two routes are not the same.

85
00:06:57,890 --> 00:07:04,490
They are different even though they have the same route by different HTTP method.

86
00:07:04,520 --> 00:07:11,420
So lastly, if you want to delete a post, you also use what is called delete method.

87
00:07:11,810 --> 00:07:19,220
You can see that the menu are it is same as this, but the difference here is the HTTP method.

88
00:07:19,400 --> 00:07:26,510
So now that we have this concept in mind, the next video, let's get back to Visual City Code and implement

89
00:07:26,510 --> 00:07:29,240
all this route inside our server.

