- [Instructor] So we've seen how to use post requests
to carry extra information in the form of adjacent object,
along with the requests we send to our server,
and this is generally the best way
to add information to our requests,
but there are several other ways to do so as well,
before we move on to implementing features like
adding things to users carts on our site,
we're going to take a backward look at
a concept that we learned when
implementing the product detail page for our front end.
Remember that for our product detail page
we simply use the same component,
but loaded in different data
depending on the ID property up here in the URL.
And remember that how we did this was by defining our RAWT
with a little ID thing like that,
which basically meant that the value of this portion
of the URL got passed through to our component
when it was rendered and allowed us to use
the ID to load the correct product.
And you might remember also that using pieces of the URL in
this way is called URL parameters
or sometimes RAWT parameters.
As a matter of fact,
express also allows us to use URL parameters
and this is useful in many cases for example,
if we want to get a given products data from the backend,
we'd be able to make a get request
to an end point that would look something like this,
we might say products slash one, two, three,
where the one, two, three is the products ID.
Or if we wanted to load data for the user's cart,
we could make a get request to
slash users slash one, two, three, four, five, where that's
the user's ID potentially, and then slash cart.
And in these examples, what our express server would do
is it would parse out that ID property from the URL,
and then it would provide that to the callback logic
that we're using inside our server endpoints.
So let's take a look at exactly how this is done.
Let's use the same simple example that
we used in our last video, simply returning a hello message
with the name that we pass through appended to it.
And basically what we want to do
is we want it to be a get request without any request body.
And we want to just be able to send a
get request to slash hello, slash our name,
and then we want to see it respond
with this same response when we do that.
To do this let's define a new get RAWT on our app,
so we're going to say app dot get
and then as far as the URL goes
we're going to put slash, hello, slash and then call a name
since we can call these URL parameters anything we want.
And then inside our callback function,
which is going to look like this request response.
What we're just going to say is res dot send,
we're going to use back ticks here
and we're going to say hello,
And the way that we access the value of this name
part of the URL is by saying request, dot params, dot name.
And now if we rerun our server with NPX Babel node
source server dot JS,
and then if we go back to post-man
and send this get request to slash hello
slash whatever your name is and hit send,
we should see that we get back that same kind of result,
which means that our server is correctly parsing
the parameter the URL parameter here, name and
sending it back to us.
And that's all there is to it in express.