1
00:00:02,040 --> 00:00:04,780
So let's dive into this demo application

2
00:00:04,780 --> 00:00:07,640
and into networking with docker den,

3
00:00:07,640 --> 00:00:09,300
and for that, first of all

4
00:00:09,300 --> 00:00:11,400
I wanna briefly walk you through

5
00:00:11,400 --> 00:00:15,010
this node demo application which we have here.

6
00:00:15,010 --> 00:00:18,310
As I said that I'm using node as just well

7
00:00:18,310 --> 00:00:19,630
decision I made here.

8
00:00:19,630 --> 00:00:21,330
You don't have to use node,

9
00:00:21,330 --> 00:00:24,220
but this application here which is built with node

10
00:00:24,220 --> 00:00:29,080
has a couple of dependencies, axios, express, body-parser

11
00:00:29,080 --> 00:00:30,060
and mongoose

12
00:00:30,060 --> 00:00:34,260
and it uses all the dependencies and some custom code

13
00:00:34,260 --> 00:00:37,200
to in the end build a web API.

14
00:00:37,200 --> 00:00:41,160
Which basically means this is a web application

15
00:00:41,160 --> 00:00:45,490
which does not return HTML code or anything like that

16
00:00:45,490 --> 00:00:47,930
instead, it just returns data

17
00:00:47,930 --> 00:00:50,220
and it also just wants data

18
00:00:50,220 --> 00:00:53,340
when requests are sent to this API

19
00:00:53,340 --> 00:00:58,340
and this web API has four so-called endpoints.

20
00:00:58,600 --> 00:01:02,980
It accepts get requests to the API address

21
00:01:02,980 --> 00:01:05,790
or domain slash favorites.

22
00:01:05,790 --> 00:01:08,800
Post requests to the same URL

23
00:01:08,800 --> 00:01:11,470
also slash favorites at the end

24
00:01:11,470 --> 00:01:15,810
and then also get requests to this APIs IP

25
00:01:15,810 --> 00:01:20,570
or domain name slash movies and slash people.

26
00:01:20,570 --> 00:01:22,500
Now for movies and people

27
00:01:22,500 --> 00:01:26,700
we use these Star Wars dummy API I already talked about

28
00:01:26,700 --> 00:01:29,600
and we're going to send a naver HTTP request

29
00:01:29,600 --> 00:01:33,910
from inside this node API to that API.

30
00:01:33,910 --> 00:01:36,120
We don't know with which language it's build

31
00:01:36,120 --> 00:01:38,020
but that also doesn't matter to us.

32
00:01:38,020 --> 00:01:40,230
As I said, this Star Wars API

33
00:01:40,230 --> 00:01:42,810
is not owned by me, you or by us.

34
00:01:42,810 --> 00:01:45,240
It's a naver third party API.

35
00:01:45,240 --> 00:01:47,250
And we're sending a request there

36
00:01:47,250 --> 00:01:50,810
simply to then return the data fetch from this API

37
00:01:50,810 --> 00:01:54,200
in a response sent back from our own API

38
00:01:54,200 --> 00:01:56,853
to whoever requested this data.

39
00:01:57,740 --> 00:02:01,050
And that's what we're doing for movies and for people.

40
00:02:01,050 --> 00:02:04,100
But then we're all just establishing a connection

41
00:02:04,100 --> 00:02:06,200
to a MongoDB database

42
00:02:06,200 --> 00:02:09,360
and therefore you will need a running mongo database

43
00:02:09,360 --> 00:02:10,440
for this to work,

44
00:02:10,440 --> 00:02:12,470
I'll come back to that in a second.

45
00:02:12,470 --> 00:02:15,350
And with that database connection established

46
00:02:15,350 --> 00:02:17,420
in the other two endpoints,

47
00:02:17,420 --> 00:02:22,420
we store data here for the post requests to slash favorites.

48
00:02:22,520 --> 00:02:24,880
We store data in our database.

49
00:02:24,880 --> 00:02:25,713
In this case,

50
00:02:25,713 --> 00:02:29,290
we can basically bookmark our favorite movie or character

51
00:02:29,290 --> 00:02:31,530
so we can store some basic data

52
00:02:31,530 --> 00:02:34,340
about our favorite movie or character here.

53
00:02:34,340 --> 00:02:37,130
And we stored that data in the database

54
00:02:37,130 --> 00:02:40,160
by using a third party package named mongoose

55
00:02:40,160 --> 00:02:44,320
which makes this Node.js to MongoDB communication,

56
00:02:44,320 --> 00:02:45,780
a bit easier

57
00:02:45,780 --> 00:02:48,330
and for get favorites,

58
00:02:48,330 --> 00:02:50,970
I actually reach out to this database

59
00:02:50,970 --> 00:02:53,090
and I fetch some data from there.

60
00:02:53,090 --> 00:02:57,420
To be precise, I return all the favorites that were stored

61
00:02:57,420 --> 00:03:00,690
with help of this post favorites endpoint.

62
00:03:00,690 --> 00:03:03,270
That's what this application does.

63
00:03:03,270 --> 00:03:04,960
Now to see it in action

64
00:03:04,960 --> 00:03:09,000
I'll quickly do something which won't work on your system.

65
00:03:09,000 --> 00:03:11,180
I will start this application

66
00:03:11,180 --> 00:03:13,380
and it won't work on your system.

67
00:03:13,380 --> 00:03:15,270
At least not like this

68
00:03:15,270 --> 00:03:19,200
because you will need MongoDB to be installed for that.

69
00:03:19,200 --> 00:03:22,210
Now, if you absolutely want to run this application

70
00:03:22,210 --> 00:03:24,440
locally without docker first

71
00:03:24,440 --> 00:03:28,440
you can visit MongoDB.com docs server

72
00:03:28,440 --> 00:03:31,810
and then installation to learn how to install this

73
00:03:31,810 --> 00:03:36,130
locally on your system for Mac iOS, Windows and so on.

74
00:03:36,130 --> 00:03:38,340
But again, this is not required

75
00:03:38,340 --> 00:03:40,040
I will just give you a first look

76
00:03:40,040 --> 00:03:42,460
at what we're going to build throughout this module.

77
00:03:42,460 --> 00:03:44,500
You don't need to install MongoDB

78
00:03:44,500 --> 00:03:47,280
because we're going to dockerize this anyways.

79
00:03:47,280 --> 00:03:48,810
With that set though

80
00:03:48,810 --> 00:03:51,290
I got MongoDB installed up and running

81
00:03:51,290 --> 00:03:52,830
and now here in the terminal,

82
00:03:52,830 --> 00:03:55,300
I will run NPM install just like this,

83
00:03:55,300 --> 00:03:56,680
not inside of a container

84
00:03:56,680 --> 00:03:58,640
because I wanna show you this application

85
00:03:58,640 --> 00:04:00,330
without containers first.

86
00:04:00,330 --> 00:04:01,180
And with that

87
00:04:01,180 --> 00:04:05,550
I can then run node app.js to start this application

88
00:04:05,550 --> 00:04:08,340
it now connects to the database and so on.

89
00:04:08,340 --> 00:04:11,390
And to now test communicating to that API,

90
00:04:11,390 --> 00:04:12,950
I'm using postman,

91
00:04:12,950 --> 00:04:16,160
which you can download for free from postman.com.

92
00:04:16,160 --> 00:04:17,810
And that's simply a little tool

93
00:04:17,810 --> 00:04:22,533
which you can use to send HTTP requests to web APIs.

94
00:04:23,980 --> 00:04:27,480
With that installed I started postman here

95
00:04:27,480 --> 00:04:30,540
and we can now send a new HTTP request

96
00:04:30,540 --> 00:04:33,470
and I'll start with sending a get request

97
00:04:33,470 --> 00:04:35,860
to local host 3,000

98
00:04:35,860 --> 00:04:38,230
because this demo application is listening

99
00:04:38,230 --> 00:04:39,880
on port 3000

100
00:04:41,540 --> 00:04:44,720
and I'll send it to slash movies.

101
00:04:44,720 --> 00:04:48,330
And if I click send here after a while a short while

102
00:04:48,330 --> 00:04:50,530
I get back this movie's data,

103
00:04:50,530 --> 00:04:52,480
and again that is simply fetched

104
00:04:52,480 --> 00:04:55,343
from this Star Wars dummy API here.

105
00:04:56,740 --> 00:05:01,030
Now let's say I like this movie here, "A new hope."

106
00:05:01,030 --> 00:05:04,660
So what I'll do is I'll send the naver request,

107
00:05:04,660 --> 00:05:09,660
post request to local host 3000 slash favorites.

108
00:05:10,260 --> 00:05:15,160
This will target this endpoint here

109
00:05:15,160 --> 00:05:17,170
where the data then gets stored

110
00:05:17,170 --> 00:05:19,623
in my local MongoDB database.

111
00:05:20,900 --> 00:05:24,620
So with that, I need to add a body to this request

112
00:05:24,620 --> 00:05:28,690
and here I'll add a raw body in JSON format

113
00:05:28,690 --> 00:05:31,660
because this API wants data in JSON

114
00:05:31,660 --> 00:05:34,810
which is simply a text format for exchanging data

115
00:05:34,810 --> 00:05:38,150
and it's the most commonly used format for that.

116
00:05:38,150 --> 00:05:42,340
And here I then need to write curly braces

117
00:05:42,340 --> 00:05:45,870
and then provide free key value pairs.

118
00:05:45,870 --> 00:05:48,080
I need to add a name, a type,

119
00:05:48,080 --> 00:05:51,843
and a URL field to my request data.

120
00:05:53,290 --> 00:05:56,770
So here I add name between double quotes

121
00:05:56,770 --> 00:05:59,470
then type between double quotes

122
00:05:59,470 --> 00:06:02,680
and URL between double quotes

123
00:06:02,680 --> 00:06:05,580
and the URL can now be found

124
00:06:05,580 --> 00:06:09,260
from my response here on the first request to be sent.

125
00:06:09,260 --> 00:06:12,550
Here I'm going to grab this URL

126
00:06:13,620 --> 00:06:15,263
to this specific movie.

127
00:06:16,340 --> 00:06:18,380
The name was also returned there

128
00:06:18,380 --> 00:06:20,777
so I'm going to grab this name as well,

129
00:06:20,777 --> 00:06:23,830
"A new hope" like this

130
00:06:23,830 --> 00:06:25,690
add it between double quotes here

131
00:06:25,690 --> 00:06:27,710
and to type here is movie.

132
00:06:27,710 --> 00:06:29,890
And for my dummy application here

133
00:06:29,890 --> 00:06:34,140
it has to be movie or a character for any other type

134
00:06:34,140 --> 00:06:35,290
you would get an error.

135
00:06:36,370 --> 00:06:39,010
So here I'll set it to movie

136
00:06:39,010 --> 00:06:40,600
and if I now click send

137
00:06:40,600 --> 00:06:44,083
I get back this response that this favorite was saved.

138
00:06:44,950 --> 00:06:46,900
And if I now send another request

139
00:06:46,900 --> 00:06:51,610
to get local host 3000 slash favorites

140
00:06:51,610 --> 00:06:52,800
just like this,

141
00:06:52,800 --> 00:06:55,570
I now get all the favorites that were stored

142
00:06:55,570 --> 00:06:57,460
in my local database

143
00:06:57,460 --> 00:07:01,520
and with local database just to emphasize this again,

144
00:07:01,520 --> 00:07:04,360
I mean this MongoDB database

145
00:07:04,360 --> 00:07:07,130
to which I'm connecting down there in my node code,

146
00:07:07,130 --> 00:07:09,880
which is running on my host machine

147
00:07:09,880 --> 00:07:12,610
at the moment, everything is running on my host machine.

148
00:07:12,610 --> 00:07:14,690
I'm not running this node application

149
00:07:14,690 --> 00:07:16,580
in a container at the moment.

150
00:07:16,580 --> 00:07:19,760
So when I say local MongoDB database

151
00:07:19,760 --> 00:07:22,820
I really mean MongoDB which I installed

152
00:07:22,820 --> 00:07:25,690
on my machine before we started this module.

153
00:07:25,690 --> 00:07:27,640
You might not have it installed

154
00:07:27,640 --> 00:07:30,010
and therefore you can't run this code

155
00:07:30,010 --> 00:07:33,820
but we're going to put it into a container anyways.

156
00:07:33,820 --> 00:07:35,510
But I hope that for the moment,

157
00:07:35,510 --> 00:07:38,530
it's clear what this application does

158
00:07:38,530 --> 00:07:40,640
and what we can do with it.

159
00:07:40,640 --> 00:07:43,040
Now let's put it into a container

160
00:07:43,040 --> 00:07:45,970
and then see how we can still ensure

161
00:07:45,970 --> 00:07:47,670
that everything works as intended.

