1
00:00:00,330 --> 00:00:06,689
All right, so we're successfully sharing a list of items and of course, let's take a look at how we

2
00:00:06,689 --> 00:00:11,770
can provide info about that one specific product.

3
00:00:12,120 --> 00:00:19,290
So, for example, if I navigate two products and then forward slash and one, then I'm going to get

4
00:00:19,590 --> 00:00:24,210
only the info about this first product because it has the idea of one.

5
00:00:24,660 --> 00:00:31,350
And not only I'll get these three properties, but also get the description.

6
00:00:31,770 --> 00:00:38,370
And our initial approach would go something like this where, yes, I see the product look beautiful

7
00:00:39,210 --> 00:00:40,980
and we already know how to set up throughout.

8
00:00:41,340 --> 00:00:46,470
Now since I'll delete it eventually anyway, I'm just going to copy and paste so we can speed this up.

9
00:00:46,770 --> 00:00:49,920
So I'm going to go with API product and then forward slash one.

10
00:00:50,570 --> 00:00:58,650
I just mean that I'm going to be looking for item number one in here and then instead of map, we'll

11
00:00:58,650 --> 00:00:59,880
use the find method.

12
00:01:00,420 --> 00:01:06,690
So I'm importing all my product and in order to get the single product, I'm going to write the following

13
00:01:06,690 --> 00:01:13,790
code where we're going to go with const single product and the worry we will reuse this code.

14
00:01:13,800 --> 00:01:17,520
So it's not like we are just randomly typing something.

15
00:01:17,880 --> 00:01:26,310
So let's go with products and then find out again our reference, each product with a parameter of product

16
00:01:26,730 --> 00:01:28,050
in my callback function.

17
00:01:28,380 --> 00:01:38,990
And if the product is the product, ID matches one because that is my route here, then of course our

18
00:01:39,010 --> 00:01:40,340
return, not single product.

19
00:01:40,770 --> 00:01:44,540
So I'm going to say single product and technically this works.

20
00:01:45,090 --> 00:01:53,370
So notice now of course, I have only info about this one specific product and I have the description.

21
00:01:53,700 --> 00:01:57,350
However, it feels like using bazooka on a cockroach.

22
00:01:57,750 --> 00:02:05,820
Yeah, I'd get the job done, but probably is an overkill because keep in mind, at the moment we have

23
00:02:06,240 --> 00:02:07,250
only four products.

24
00:02:07,680 --> 00:02:12,870
So yes, if I really wanted to, I could set up for Route's.

25
00:02:13,840 --> 00:02:16,390
But what if I have hundred, two hundred, three hundred?

26
00:02:16,840 --> 00:02:18,330
Well, that's not going to work.

27
00:02:18,700 --> 00:02:24,880
And an express we have something called aroud parameters, which essentially is going to be way better

28
00:02:24,880 --> 00:02:25,470
solution.

29
00:02:25,870 --> 00:02:34,420
So instead of hard coding this one, two, three, or whatever it is would want, we set up a root parameter

30
00:02:34,750 --> 00:02:39,970
and it's going to look something like this where I go with my route and then I have four words and then

31
00:02:39,970 --> 00:02:44,220
I go with column and then whatever name our one.

32
00:02:44,500 --> 00:02:47,110
So think of this as a placeholder.

33
00:02:47,350 --> 00:02:50,310
So you can call this Bobbie Lee, you can call this chicken burrito.

34
00:02:50,620 --> 00:02:53,530
In my case, I'm going to go with product.

35
00:02:53,920 --> 00:03:00,870
And the idea is just to be explicit off what I am expecting over here.

36
00:03:01,150 --> 00:03:04,090
But again, naming here is really up to you.

37
00:03:04,690 --> 00:03:08,380
And what is more important is the fact how we can access it.

38
00:03:08,710 --> 00:03:12,570
Now, if you want, you can actually log of the request object.

39
00:03:12,580 --> 00:03:15,220
Again, this is just going to be a giant object.

40
00:03:15,430 --> 00:03:18,040
And for now, I'm just going to leave this one there where it is.

41
00:03:18,370 --> 00:03:22,300
So I'm still going to be returning a product, number one.

42
00:03:22,540 --> 00:03:29,710
And also, let's look for a request and then we're looking for the program's property.

43
00:03:30,040 --> 00:03:33,760
So let me log this one and then going to want to navigate back.

44
00:03:34,000 --> 00:03:42,400
And if I refresh in the API product number one, which you'll notice again, this giant request object

45
00:03:42,640 --> 00:03:45,610
where we have a bunch of useful properties and methods.

46
00:03:45,910 --> 00:03:48,760
And of course, I'm not going to cover all of them right now.

47
00:03:48,970 --> 00:03:57,430
But similar to HTP, of course, in the Express, we also have access to a bunch of useful things in

48
00:03:57,430 --> 00:04:01,660
that request object, and one of them is the primes.

49
00:04:02,110 --> 00:04:02,840
So check it out.

50
00:04:03,160 --> 00:04:07,680
Now I have this productivity and the value is one.

51
00:04:08,020 --> 00:04:14,890
Now, please keep in mind one thing that whatever you're going to be setting up here in the role as

52
00:04:14,890 --> 00:04:19,600
that parameter is always going to come back as a string.

53
00:04:20,140 --> 00:04:27,040
And this is important in this case, because if you take a look at our data, the idea is a number.

54
00:04:27,490 --> 00:04:29,830
And of course, we'll deal with that in a second.

55
00:04:30,280 --> 00:04:38,110
And whatever we set up as far as our name is going to be right in here is going to be in this request

56
00:04:38,350 --> 00:04:40,150
and then programmers object.

57
00:04:40,450 --> 00:04:47,410
So now, of course, what I could do is I could use the structure from the programs and then use it

58
00:04:47,410 --> 00:04:51,970
in order to find that specific product so that I don't have to.

59
00:04:51,970 --> 00:04:56,350
Hard code products, number one, product number two, and on and on and on.

60
00:04:56,560 --> 00:05:02,350
Instead, I just set up my root parameter and just come up with whatever name I would want.

61
00:05:02,860 --> 00:05:09,880
Just make sure that you this call in here and then will access that value and get a specific product.

62
00:05:10,150 --> 00:05:16,720
So I'll leave these two suckers for your reference, just in case you ever want to log them.

63
00:05:17,020 --> 00:05:24,490
And we'll simply go with CONSED and the name is Product ID and that is equal to request.

64
00:05:25,430 --> 00:05:33,350
That's my request object, and perhaps then I'm going to use this product idea to get my product, but

65
00:05:33,350 --> 00:05:35,990
remember, it is a strength.

66
00:05:36,410 --> 00:05:37,490
We can clearly see that.

67
00:05:37,760 --> 00:05:43,270
And in fact, here in the array, well, the IDs are numbers.

68
00:05:43,580 --> 00:05:48,830
So if you'll just try to search it the way it is, of course, we won't be able to get our product.

69
00:05:49,130 --> 00:05:54,380
So instead, what we want is price in the number and product.

70
00:05:55,200 --> 00:06:03,010
Now, of course, if your IDs are set up Strang's, which is somewhat typical setup for the databases

71
00:06:03,020 --> 00:06:07,180
and all that, as well as the adolescences, then of course you don't need to worry about it.

72
00:06:07,520 --> 00:06:09,560
Then you can just pass in the string.

73
00:06:09,830 --> 00:06:14,330
And now, of course, I'm going to be able to get my one product.

74
00:06:14,720 --> 00:06:23,870
So now if I go back and if I refresh, everything still works and if I go to my URL and start changing

75
00:06:23,870 --> 00:06:26,600
these values, hopefully you can say that now.

76
00:06:26,600 --> 00:06:29,570
Of course, I'm getting a different product now.

77
00:06:29,570 --> 00:06:34,700
I'm getting product number two and I go to product number three and on and on and on.

78
00:06:35,030 --> 00:06:41,970
So now with these few simple lines of code, I can access any product in my area.

79
00:06:42,290 --> 00:06:47,420
Now, of course, there's also a case where we cannot find the product because keep in mind here, I

80
00:06:47,420 --> 00:06:50,630
can type whatever I would want so I can go with products.

81
00:06:50,630 --> 00:06:54,410
And then let's imagine that the user types A.B.C..

82
00:06:54,860 --> 00:06:58,250
Now, do we have a product with an idea of ABC?

83
00:06:58,740 --> 00:06:59,880
Of course, the answer is no.

84
00:07:00,320 --> 00:07:02,090
So what's happening over here now?

85
00:07:02,090 --> 00:07:03,330
I don't get anything back.

86
00:07:03,360 --> 00:07:03,600
Right.

87
00:07:03,950 --> 00:07:11,690
Well, I don't get anything back because if I go to log and one single product, let's see what we're

88
00:07:11,690 --> 00:07:12,610
going to get back again.

89
00:07:12,860 --> 00:07:14,510
Let me refresh ABC.

90
00:07:14,840 --> 00:07:16,460
And this one is undefined.

91
00:07:16,760 --> 00:07:20,700
So that's what we're sending back as a single product.

92
00:07:21,020 --> 00:07:22,620
So what would be a solution?

93
00:07:23,000 --> 00:07:29,150
Well, a solution is setting up a statement where I say, get me the single product.

94
00:07:29,570 --> 00:07:37,040
If you cannot find that single product, if basically that product doesn't exist, if the ID that the

95
00:07:37,040 --> 00:07:44,060
user passed in does not make sense, you cannot find the product with that ad, then return for all

96
00:07:44,060 --> 00:07:44,400
four.

97
00:07:44,750 --> 00:07:46,290
So how is that going to look like?

98
00:07:46,310 --> 00:07:50,030
Well, you can go here if and then single product.

99
00:07:50,450 --> 00:07:56,630
So we set up a condition and of course I'm going to go with if a single product doesn't exist.

100
00:07:56,630 --> 00:07:58,640
So I'm going to add one point.

101
00:07:59,000 --> 00:08:01,450
And of course, this is going to be our case with undefined.

102
00:08:01,940 --> 00:08:07,750
This will be true if it is undefined and then we just go with a return address.

103
00:08:07,760 --> 00:08:12,590
And in this case, I will add a status, because that is extremely important that I go with four or

104
00:08:12,590 --> 00:08:16,790
four and then we go with sand and product.

105
00:08:17,890 --> 00:08:18,520
Does not.

106
00:08:19,410 --> 00:08:21,460
Does not exist.

107
00:08:21,960 --> 00:08:30,760
So now if everything is correct, then, of course, we go with arrest and so on here I say return and

108
00:08:30,760 --> 00:08:32,140
raise that.

109
00:08:32,140 --> 00:08:39,190
Drayson So once I go right now to product and then A, B, C, there is now of course, I have proper

110
00:08:39,190 --> 00:08:41,590
forum for product does not exist.

111
00:08:41,590 --> 00:08:50,320
And if I can take a look at the tab and I have my ABC now, if I'm going to navigate to a route where

112
00:08:50,320 --> 00:08:55,710
I can find the product, then of course I'm going to get my proper product response.

113
00:08:56,140 --> 00:09:01,000
So whenever you think of route parameters, think of them as placeholders.

114
00:09:01,270 --> 00:09:09,790
Where a user provides a data and then using requests and primes, we can access that data and then set

115
00:09:09,790 --> 00:09:11,200
up some kind of logic.

