Welcome back.
Let's get started with press routing.
So what is it?
Well, it refers to determine how an application responds to a client's request for a specific endpoint,
which is a URL or path and a specific HTTP request method that is Gates, post, delete, and so on
and so on.
So routing simply means how a user can get a response after the person has made a request, or in short,
is a way of getting a resource.
So from the previous video about demonstrating this application, you can see that when I want to fetch
or post, I provide what is called the route, and this route comprises of the HTTP method and then
the you are.
So when I send the help of the routes, I'm able to get the resources that I'm requesting for.
So now let's dive in more to talk about what is called the HTTP method.
The technical term here or the key term here is what you call the HTTP method.
What is HTTP method?
At HTTP methods are the actions that can be performed on a resource.
The most common HTTP methods are gates, post, put, patch and delete, and that is what we have specified
here.
So it's an action of getting a resource.
What action do you want to take?
Do you want to delete a record or a resource or do you want to create or do you want to update or do
you want to delete?
This is what you call an action.
So the action that you take determined by the HTTP method.
Now let's have a look at the component of a route.
A route is made up of what first is we have what is called the main you are URL.
So back to the project here.
Looking at this one, the main you are URL is from here up to here.
Anything after for slash is what we call a resource.
So for this, let's assume that we have developed application and in light production we have the URL.
So this is what we call the main you are URL.
Now for this application, there must be a lot of resources, let's say post or courses or users or
comments.
So what kind of resource do you want to fetch or do you want to play around with it?
So let's say that in your case you are going to play around or fetch all posts and this is what you
call resources.
So back to this one.
If we see that we have the menu URL and then forward slash.
All right.
And then this what you call the resources.
So when I remove the resources here and I say you can see that I guess something strange here, meaning
that there is no resources matching this route.
So if I provide, let's say one, it means that I'm fetching one.
And in that case there is no route handling this.
So if I make a search, definitely I get an error.
But if I provide post is a resource and when I make the request I get the resource.
So anything after for Slash is what you call a resource.
And the action that you want to take is what we call get because that means that getting something from
the server and this is what we call the HTTP method.
So the combination of the HTTP method menu are URL and the resource make up what is called the root
or endpoint.
So if you hear me saying root, I'm referring to endpoint.
In layman's understanding of endpoints, we often say you are URL, but as a programmer we need to speak
programming technical terms.
All right.
So now let's explain more about the HTTP methods.
So let's say that we have developed an application where we create post, fake post and delete all posts.
Let's look at the root with it respective HTTP method.
So for this one, let's say that for this application that we build, it is about posts.
So this is what we call the resources to fetch all posts and we have a method called get meaning.
Fetching means that we need to use what get request or get a HTTP method.
So what about if I want to fetch a single record?
Looking for a single look at the root here the menu.
Ah, plus resources and then plus an ID.
So looking at this route here, there are differences between the first one and the second one.
They all start from where the main you are arrow and then to this end point here.
Now this one is a resource and after that we have a slide with semicolon here.
And this is also a resource because it also comes after four slash, but instead we have colon here,
then we added ID.
So this is what you call params, right?
Because we don't know what kind of posts a user is trying to face.
So the ID might be dynamic.
So anything after colon like this is what we call params.
So for this one, the params here is one because for this one it matches the exact route here.
So for this one too, we are going to use what is called gate request.
So what about if you want to create, look here for create, you provided a post request and then the
route.
So when I hit send with the post, it means that I'm able to create a resource and save it onto the
server and we use what is called post HTTP method.
Then what about if I want to update, we are going to use HTTP method called put.
So looking at this route here for PWD and then forget a single record or post, we see that they follow
the same route with the post with some ID.
So these two routes are different because of the HTTP method.
So these two routes are not the same.
They are different even though they have the same route by different HTTP method.
So lastly, if you want to delete a post, you also use what is called delete method.
You can see that the menu are it is same as this, but the difference here is the HTTP method.
So now that we have this concept in mind, the next video, let's get back to Visual City Code and implement
all this route inside our server.