1
00:00:00,660 --> 00:00:09,870
Once we're familiar with the most basic setup, let's build a more meaningful API and in the process

2
00:00:09,870 --> 00:00:15,510
we'll cover broad parameters as well as query string parameters.

3
00:00:15,900 --> 00:00:21,960
And I would want to start in the following way where essentially I'll leave all this code.

4
00:00:22,320 --> 00:00:29,820
But when it comes to my route, when it comes to my homepage, I'll essentially send back the one with

5
00:00:29,820 --> 00:00:31,410
the link as well.

6
00:00:31,650 --> 00:00:39,870
And that link will direct a user to a fourth slash API and then product and then later will cover the

7
00:00:39,870 --> 00:00:42,640
programs as well as the query string.

8
00:00:43,020 --> 00:00:45,830
So let's start with sending back the email instead.

9
00:00:46,080 --> 00:00:50,350
So I'm not going with just one one and I'm not going to send back the file.

10
00:00:50,700 --> 00:00:52,680
I'll go directly and I'll say send.

11
00:00:53,010 --> 00:00:54,390
And here we have the string.

12
00:00:54,390 --> 00:00:59,300
Of course I'm going to go with one and then home page.

13
00:00:59,730 --> 00:01:04,560
Then I'll make sure that I close because I believe in one of the previous videos.

14
00:01:05,040 --> 00:01:08,360
I believe it was the express basics.

15
00:01:08,760 --> 00:01:09,970
I think I messed that up here.

16
00:01:09,990 --> 00:01:13,080
Notice I didn't add the closing one.

17
00:01:13,200 --> 00:01:14,820
So now everything is correct.

18
00:01:15,180 --> 00:01:16,890
And now I'm going to go with my link.

19
00:01:17,400 --> 00:01:25,500
Then as far as the traffic, I'm going to direct a user to API and then forward slash products.

20
00:01:26,040 --> 00:01:27,150
And then, of course.

21
00:01:28,320 --> 00:01:35,080
I will also set up a text here so products and I'll close my link so that you do it.

22
00:01:35,100 --> 00:01:36,810
That is my home page.

23
00:01:37,050 --> 00:01:40,860
And of course, if I go to localhost five thousand, there it is.

24
00:01:40,860 --> 00:01:45,680
I have my own page and once I click the link, I navigate to API product.

25
00:01:46,020 --> 00:01:53,430
And of course, the moment I have the default response from the express, meaning the default for or

26
00:01:53,430 --> 00:01:57,600
for response where the resource cannot be found.

27
00:01:57,810 --> 00:02:01,470
And as I said, if you want to take a look, what response do they send?

28
00:02:01,470 --> 00:02:04,530
Are going to go to the network is going to be very, very useful.

29
00:02:04,710 --> 00:02:07,890
Tab refresh and take a look at their response.

30
00:02:08,280 --> 00:02:09,630
So notice the response.

31
00:02:09,840 --> 00:02:12,990
That's the e-mail that they sent back.

32
00:02:13,320 --> 00:02:16,220
So kind of get an API products.

33
00:02:16,230 --> 00:02:24,000
Now we already know why that is this get the preverb because that's the method that the browser performs.

34
00:02:24,060 --> 00:02:24,670
OK, awesome.

35
00:02:24,930 --> 00:02:26,280
So now, of course, our job.

36
00:02:27,090 --> 00:02:37,320
Is to set up a get request for this resource, so we go with our budget and I specifically want to handle

37
00:02:37,320 --> 00:02:39,360
API and product.

38
00:02:39,510 --> 00:02:43,260
So this one just looks a little bit more realistic.

39
00:02:43,500 --> 00:02:46,020
So on here I go with API and product.

40
00:02:46,020 --> 00:02:49,050
And keep in mind, of course, those values need to match.

41
00:02:49,260 --> 00:02:51,330
Otherwise, you'll get about four or four.

42
00:02:51,610 --> 00:02:56,410
Then I have my callback function and of course I would want to send back the product.

43
00:02:56,430 --> 00:03:02,730
However, in this case, we'll make it a little bit different where previously notice the product we

44
00:03:02,730 --> 00:03:04,290
send back pretty much the whole thing.

45
00:03:04,300 --> 00:03:04,620
Right.

46
00:03:04,980 --> 00:03:11,790
But a more realistic approach is following where when you are requesting a bunch of data.

47
00:03:11,820 --> 00:03:18,270
So when you're requesting a collection of the data, you're not always returning everything for that

48
00:03:18,270 --> 00:03:19,410
one specific product.

49
00:03:19,590 --> 00:03:22,290
And to give you a real world example.

50
00:03:22,630 --> 00:03:28,140
Again, I'm going to go back to my Riak project and I'm simply using them because this gives you a visual

51
00:03:28,140 --> 00:03:29,040
representation.

52
00:03:29,460 --> 00:03:34,560
During the course, we build a ecommerce and in the products page.

53
00:03:34,920 --> 00:03:36,810
Notice how we're fetching the product.

54
00:03:37,380 --> 00:03:43,980
But you need to keep in mind one thing where we're only fetching about the product, the title, the

55
00:03:43,980 --> 00:03:47,520
price, the image, and I believe also the idea.

56
00:03:47,910 --> 00:03:54,660
And only when I go to that single product page, this is where I get the rest of the data, whether

57
00:03:54,870 --> 00:04:02,910
that is, for example, a stars that reviews the description, the availability and all that stuff.

58
00:04:02,940 --> 00:04:09,240
So what I'm trying to say is when you're requesting a collection of data, there's going to be cases

59
00:04:09,240 --> 00:04:13,270
where I simply want to send back some minimal response.

60
00:04:13,620 --> 00:04:17,480
So, for example, again, that could be name image and the price in this scenario.

61
00:04:17,910 --> 00:04:26,280
And only if I look for this specific product, then I send back everything and not remembering that

62
00:04:26,430 --> 00:04:29,400
in our example, in this response.

63
00:04:30,290 --> 00:04:36,590
What I'm going to do is I'm just going to iterate over my product, I'll use the map method and I'll

64
00:04:36,590 --> 00:04:39,640
just remove my description.

65
00:04:39,950 --> 00:04:44,210
So when I'm sending back the product, it's going to be without a description.

66
00:04:44,510 --> 00:04:50,480
So, again, if we were to send back everything, I would simply go with response, Jason, and then

67
00:04:50,480 --> 00:04:51,800
I pass in the product.

68
00:04:52,100 --> 00:04:56,300
So, again, if we go here and if you refresh now, everything's cool.

69
00:04:56,570 --> 00:04:59,810
I'm getting my product on the API product.

70
00:05:00,500 --> 00:05:07,910
However, I'm going to make it a bit more realistic and we're going to go consed new product is equal

71
00:05:07,910 --> 00:05:15,830
to product update maps and mapping over and I'm creating a new era and I'll reference each item as a

72
00:05:15,830 --> 00:05:16,310
product.

73
00:05:16,490 --> 00:05:17,990
And then as far as the return.

74
00:05:18,200 --> 00:05:20,540
Well first out one of the structure.

75
00:05:20,780 --> 00:05:27,740
The properties are of the product and the reason why I can access them is because those are the names

76
00:05:27,740 --> 00:05:29,690
that I used when I was setting it up.

77
00:05:29,690 --> 00:05:32,680
So I'd name image and all that.

78
00:05:32,880 --> 00:05:34,820
And that is equal to the product.

79
00:05:34,850 --> 00:05:40,460
Again, I'm just using simple JavaScript structuring and then as far as the return, whatever, I'm

80
00:05:40,460 --> 00:05:45,510
going to return from my function, well, that is going to be the new value.

81
00:05:45,800 --> 00:05:49,370
So now I'm going to go with IDE name as well as the image.

82
00:05:49,670 --> 00:05:55,550
And once I have this setup in place instead of returning products, now of course I'm going to go with

83
00:05:55,550 --> 00:06:05,420
new products and if I go back to my browser Verity's so now I'm getting a collection but I'm not sending

84
00:06:05,720 --> 00:06:12,110
everything that I know about the specific item, so I'm being selective of what I'm sending back.

85
00:06:12,440 --> 00:06:18,200
So yes, there is a resource by the name of API product and we're sending back the array.

86
00:06:18,440 --> 00:06:26,660
But we know that if the user wants to access that description, he or she will have to look for specific

87
00:06:26,660 --> 00:06:32,360
product and in the process we'll cover what are the you are all parameters.

