1
00:00:00,210 --> 00:00:06,590
Hello, everyone, and welcome to this new and exciting session in which we are going to look at APIs.

2
00:00:06,600 --> 00:00:07,140
Now.

3
00:00:07,140 --> 00:00:10,980
API stands for Application Programming Interface.

4
00:00:11,430 --> 00:00:18,330
And in this section we're going to look at why we even need APIs and also how they work.

5
00:00:18,480 --> 00:00:27,300
Now, supposing you've just built this model right here, let's call this Model M one, and this model

6
00:00:27,300 --> 00:00:31,620
can take in an input and produce an output.

7
00:00:31,800 --> 00:00:40,710
The question is how do I make my web app like this one or my mobile app or even my desktop app access

8
00:00:40,710 --> 00:00:52,740
this model which have built such that a user of, let's say this mobile app can just by pressing a button,

9
00:00:52,740 --> 00:00:55,260
get access to this.

10
00:00:55,260 --> 00:01:02,820
My model's predictions the way we could go about this is by making use of APIs.

11
00:01:02,820 --> 00:01:12,210
That's application programming interfaces as defined here the G two dot com website and API permits

12
00:01:12,210 --> 00:01:19,140
software development and innovation to be easier by allowing programs.

13
00:01:19,140 --> 00:01:26,670
That is, for example, your web apps to communicate data and functions safely and quickly.

14
00:01:27,090 --> 00:01:33,420
APIs Does application programming interfaces accelerate innovation because more developers can build

15
00:01:33,420 --> 00:01:37,470
products based on existing data and functionality?

16
00:01:38,280 --> 00:01:40,180
Getting back to our example.

17
00:01:40,200 --> 00:01:50,820
This means that thousands of users now on the web can get access to our model and make predictions.

18
00:01:50,820 --> 00:02:01,230
Without this, developers of this web apps or mobile apps necessarily Mastering the art of model creation.

19
00:02:01,320 --> 00:02:03,540
So we can make this concepts clearer.

20
00:02:03,570 --> 00:02:05,220
Let's take this example.

21
00:02:05,220 --> 00:02:11,700
So yeah, we supposing that you get into a restaurant, you give a command to the waiter, would then

22
00:02:11,700 --> 00:02:18,620
take this command and then tells the cooks to make available the food you have in the command.

23
00:02:18,630 --> 00:02:23,310
Then once this food is ready, it sends it back to the waiter.

24
00:02:23,310 --> 00:02:24,600
That's the API.

25
00:02:24,600 --> 00:02:31,110
And then the waiter now passes on this food to you who then eats it and is happy.

26
00:02:31,140 --> 00:02:38,610
Now, in the case of computer software where we have, say, this mobile app which has to communicate

27
00:02:38,610 --> 00:02:47,280
with this API right here, then this communication has to follow certain rules or a protocol known as

28
00:02:47,280 --> 00:02:49,140
the HTTP.

29
00:02:50,130 --> 00:02:55,800
This protocol guides the way information is being transmitted via the web.

30
00:02:55,980 --> 00:03:00,990
Now, HTTP stands for Hypertext Transfer Protocol.

31
00:03:00,990 --> 00:03:04,530
So this hypertext, then transfer protocol.

32
00:03:04,950 --> 00:03:10,390
Now, the type of data exchange could be text, could be images, could be video.

33
00:03:10,390 --> 00:03:18,960
It could be any kind of data, which is understandable by both this client right here and the server.

34
00:03:19,110 --> 00:03:24,500
Also, communication following this HTTP protocol is connection less.

35
00:03:24,510 --> 00:03:32,940
That is, each time this client needs to communicate with the server to know what objects are found

36
00:03:32,940 --> 00:03:34,620
in the particular image.

37
00:03:34,620 --> 00:03:37,290
A connection is created between these two.

38
00:03:37,560 --> 00:03:43,500
Now, once the connection is created and then the client receives the output, that is the particular

39
00:03:43,500 --> 00:03:48,810
location where the objects are found in an image, that connection is closed.

40
00:03:49,470 --> 00:03:53,040
And so we we now have this which is taken off here.

41
00:03:54,090 --> 00:04:00,450
Then once we want to connect again with the API, which is found in the server, we still create or

42
00:04:00,450 --> 00:04:02,190
recreate another connection.

43
00:04:02,700 --> 00:04:09,690
Then also, as we have said, the data exchange here isn't of a particular type.

44
00:04:09,690 --> 00:04:18,450
So really this protocol doesn't force you to pass or receive a certain type of data so far as the data

45
00:04:18,480 --> 00:04:24,600
you're passing or receiving is understood by the particular entity which is sending or receiving.

46
00:04:25,590 --> 00:04:27,750
Then everything works just fine.

47
00:04:28,200 --> 00:04:33,350
Then the last property of HTTP protocol is it's actually stateless.

48
00:04:33,360 --> 00:04:38,680
That is, once you make a request and then you receive a response.

49
00:04:38,700 --> 00:04:43,650
No client information has been stored in this request response cycle.

50
00:04:44,190 --> 00:04:53,130
Hence, once data has been passed to the API and the response received, you should not expect to be

51
00:04:53,130 --> 00:04:56,800
able to retrieve this data which was being passed to the server.

52
00:04:56,820 --> 00:04:59,820
From this point we are going to go in depth into how.

53
00:05:00,410 --> 00:05:01,460
HTTP works.

54
00:05:02,180 --> 00:05:06,460
So you get to this address w w dot postman dot com.

55
00:05:06,470 --> 00:05:11,960
You could sign in or sign up in case you do not have an account with Postman.

56
00:05:11,990 --> 00:05:14,210
Now I have an account, so I'm just going to sign in.

57
00:05:14,240 --> 00:05:15,740
You get to this point here.

58
00:05:15,740 --> 00:05:19,220
You see you have workspaces, my workspace.

59
00:05:19,220 --> 00:05:24,170
And then you have this link here which comes by default.

60
00:05:24,170 --> 00:05:30,470
You have this URL, which is this information you pass in each time you want to gain access to a particular

61
00:05:30,470 --> 00:05:31,160
site.

62
00:05:31,340 --> 00:05:34,860
In this case, it's Postman Echo dot com.

63
00:05:34,880 --> 00:05:39,110
Now your URL actually stands for Uniform Resource Locator.

64
00:05:39,110 --> 00:05:50,240
And so this address right here permits us to get access to certain resources which are located somewhere

65
00:05:50,240 --> 00:05:51,650
in the web.

66
00:05:52,010 --> 00:05:55,190
And this brings us to the HTTP methods.

67
00:05:56,330 --> 00:06:00,680
If you click right here, you'll see that we have different options, like if you have you have the

68
00:06:00,680 --> 00:06:05,930
gate, you have the post, you have the port, you have the patch, and so on and so forth.

69
00:06:06,980 --> 00:06:09,440
These are known as the HTTP method.

70
00:06:10,100 --> 00:06:17,390
And each time you want to get access to a resource which is located somewhere in the web, you have

71
00:06:17,390 --> 00:06:19,440
to specify the exact method.

72
00:06:19,460 --> 00:06:26,450
So like with a gate, for example, we are saying that we want to get a resource for the post, unlike

73
00:06:26,450 --> 00:06:32,810
the get method, where our main interest is to retrieve some data.

74
00:06:33,620 --> 00:06:43,280
Here we submit an entity to the specified resource which often causes a change in status or side effects

75
00:06:43,280 --> 00:06:44,780
at the level of the server.

76
00:06:45,470 --> 00:06:52,520
So this means that we could make use of the get method when we want to retrieve a user's information

77
00:06:53,480 --> 00:07:00,290
and then we can make use of the post when we want to modify some data or add information.

78
00:07:00,290 --> 00:07:06,650
So like for example, if you want to get registered on a platform, then we make use of this post request

79
00:07:06,890 --> 00:07:10,340
as we're going to add a row on the database.

80
00:07:10,340 --> 00:07:18,500
So suppose we have this database right here where we have the user's ID, we have the user's name and

81
00:07:18,500 --> 00:07:20,690
for example, the user's password.

82
00:07:20,840 --> 00:07:30,080
So here we have this small database and then we have ID, let's say ID zero, we have the name friend

83
00:07:30,080 --> 00:07:31,430
and password.

84
00:07:31,430 --> 00:07:40,640
Let's say whatever value we have here now then we have ID one, let's say Sally, and then we have whatever

85
00:07:40,640 --> 00:07:41,570
password here.

86
00:07:41,780 --> 00:07:43,220
Then we could take two.

87
00:07:43,250 --> 00:07:51,770
We have Rita and we have whatever name we want to have here or whatever password want to have here.

88
00:07:51,770 --> 00:07:52,890
So this is it.

89
00:07:52,940 --> 00:08:00,950
Now, with the get request, we could just retrieve that Fred has an ID of zero.

90
00:08:01,010 --> 00:08:04,370
This name is Fred and the password is a given password.

91
00:08:04,370 --> 00:08:09,860
Whereas with the post request, we could add a new user.

92
00:08:09,860 --> 00:08:14,360
So that's why this pick, of course, and the change in state or side effects on the server.

93
00:08:14,360 --> 00:08:20,180
So we could actually add this new user by passing new information via this post request.

94
00:08:20,180 --> 00:08:27,620
So you could add this third and we could add say Mac, let's say Mac and that's it.

95
00:08:27,740 --> 00:08:30,290
So that's it for the post request.

96
00:08:30,320 --> 00:08:34,090
Now with the put request, we could update this data.

97
00:08:34,100 --> 00:08:42,650
So this means that here we could say we're not interested in maybe modifying the name, but if want

98
00:08:42,650 --> 00:08:47,840
to update this password, we could change this password now to some new password.

99
00:08:48,110 --> 00:08:53,470
So now we could update this row right here and the database.

100
00:08:53,480 --> 00:08:59,750
Now we could also delete, so we could just simply take this off with our delete request and that will

101
00:08:59,750 --> 00:09:02,270
be it for that row.

102
00:09:02,270 --> 00:09:09,770
We also have other methods like the head, the Connect Options, Trace and Patch, which you could check

103
00:09:09,770 --> 00:09:11,960
out in this document right here.

104
00:09:12,620 --> 00:09:17,120
But most times we make use of the get post, put and delete.

105
00:09:17,780 --> 00:09:22,190
Then also this responses have some status codes which we have seen already.

106
00:09:22,190 --> 00:09:26,840
So you maybe have seen a 200 or four.

107
00:09:26,840 --> 00:09:27,230
Okay.

108
00:09:27,230 --> 00:09:29,780
So okay, we make a request and it's okay.

109
00:09:29,780 --> 00:09:31,280
You could receive that.

110
00:09:31,280 --> 00:09:34,790
Let's, let's make this request here you are all empty.

111
00:09:34,790 --> 00:09:35,960
Let's get back here.

112
00:09:35,960 --> 00:09:37,970
And you see, you see your status.

113
00:09:37,970 --> 00:09:39,590
Let's highlight this.

114
00:09:39,590 --> 00:09:40,490
You see a status.

115
00:09:40,490 --> 00:09:41,300
Okay.

116
00:09:41,300 --> 00:09:46,490
So this as we have seen here, let's get back.

117
00:09:47,690 --> 00:09:51,710
This has, as we have seen here, HTTP response status codes.

118
00:09:51,710 --> 00:09:58,280
So you could again check in this documentation and have every detail about the different status codes.

119
00:09:58,280 --> 00:09:59,810
And you need to understand how to.

120
00:09:59,930 --> 00:10:03,290
Work with them as they're very important when you're dealing with APIs.

121
00:10:03,290 --> 00:10:09,650
So we have information, our responses, successful responses lie in between 202 99, and that's why

122
00:10:09,650 --> 00:10:11,690
you see here we have this 200.

123
00:10:13,340 --> 00:10:17,330
Status code, which is a success.

124
00:10:17,900 --> 00:10:22,750
And then we have redirections, we have client error, and we have several error.

125
00:10:22,760 --> 00:10:28,730
So if this error is coming from the person sending the API request, then you'll be between 404 and

126
00:10:28,730 --> 00:10:29,480
99.

127
00:10:29,720 --> 00:10:32,540
The errors from the server will be between 505 99.

128
00:10:32,540 --> 00:10:38,000
So when the server is down, sometimes you will see this 500 so you could check your internal server

129
00:10:38,000 --> 00:10:38,420
error.

130
00:10:38,450 --> 00:10:41,600
The server is in current situation it doesn't know how to handle.

131
00:10:41,600 --> 00:10:44,260
So you could check out all this in this documentation.

132
00:10:44,270 --> 00:10:47,750
Now let's get back here and make this error.

133
00:10:47,750 --> 00:10:50,300
So let's let's put in whatever value one year.

134
00:10:50,870 --> 00:10:56,360
Write that again and you should see your c404 not found.

135
00:10:56,360 --> 00:11:01,310
So you get your you c40 for client error.

136
00:11:01,310 --> 00:11:03,890
So this error comes from the client.

137
00:11:04,040 --> 00:11:10,880
We are going to paste this out here and then select the post request, get to the body form later.

138
00:11:10,880 --> 00:11:12,890
This is the information we'll be passing in.

139
00:11:12,890 --> 00:11:24,950
So yeah, we're going to have email teams and learn that I the password, not a password and then job

140
00:11:25,640 --> 00:11:27,920
alerts and then click on send.

141
00:11:28,400 --> 00:11:29,600
Okay, What do we get?

142
00:11:29,600 --> 00:11:31,370
You see, we have this output right here.

143
00:11:31,370 --> 00:11:36,890
We have our email, the username, the job and a token status to 100.

144
00:11:37,700 --> 00:11:42,200
Now you will notice that unlike with the get requests, we have now introduced this body data.

145
00:11:42,200 --> 00:11:47,840
So if we don't pass this body data, you see that we didn't have the right output.

146
00:11:48,110 --> 00:11:54,770
And this is because to log in to just any platform, obviously you need to pass in your credentials,

147
00:11:54,770 --> 00:11:58,250
which in this case the email, the password and the job.

148
00:11:58,790 --> 00:12:05,720
So this tells us that when doing an API call like this one, so when trying to make the client communicate

149
00:12:05,720 --> 00:12:10,100
with the server, we need to specify the HTTP method.

150
00:12:10,100 --> 00:12:12,770
We need to specify the U URL.

151
00:12:12,950 --> 00:12:17,930
Then we also need to specify the body, which in this case is all this information right here.

152
00:12:17,930 --> 00:12:22,610
That is the body information and the header information.

153
00:12:22,970 --> 00:12:29,090
Now this header and body information could be broken up into the request and response.

154
00:12:29,090 --> 00:12:34,460
So this is the request body and here is a response body.

155
00:12:35,180 --> 00:12:43,340
And then here we have the request header and the response header, which you can get by simply clicking

156
00:12:43,340 --> 00:12:44,450
on this right here.

157
00:12:44,600 --> 00:12:51,740
You can also check out a list of HTTP headers in this developer dot mozilla dot org platform right here.

158
00:12:51,890 --> 00:12:58,490
Then at the level of this response headers, take note of this content type, which is JSON.

159
00:12:58,490 --> 00:13:05,570
JSON actually stands for JavaScript object notation, which is a very easy and lightweight format for

160
00:13:05,570 --> 00:13:10,820
storing and transporting data from a client to a server and vice versa.

161
00:13:11,450 --> 00:13:20,210
The JSON format is programming language independent, and so if we have a client with code reading in

162
00:13:20,210 --> 00:13:29,480
JavaScript, it can communicate JSON data to this API via this request, which is reading, for example,

163
00:13:29,480 --> 00:13:31,880
in another programming language like Python.

164
00:13:31,880 --> 00:13:41,000
And then after processing data, the response in JSON format will still be understood by this JavaScript

165
00:13:41,000 --> 00:13:41,780
client.

166
00:13:41,810 --> 00:13:48,050
Now, to better understand the JSON formatting, let's look at this output which was generated after

167
00:13:48,050 --> 00:13:53,570
we made the get request on this Postman Echo API right here.

168
00:13:54,140 --> 00:13:58,250
You would first notice that it starts and ends with this curly braces.

169
00:13:58,250 --> 00:14:08,120
So we start like this and we end this way and then we have information stored in key value pairs.

170
00:14:08,120 --> 00:14:11,300
So we have the key and then we have the value.

171
00:14:11,300 --> 00:14:14,390
And then each key value pair is separated by a comma.

172
00:14:14,390 --> 00:14:23,930
So we have the first key here key, and then we have the colon, and then we have the value, we have

173
00:14:23,930 --> 00:14:24,800
a comma.

174
00:14:24,800 --> 00:14:25,990
And then the next lesson.

175
00:14:26,000 --> 00:14:35,210
Q One value one, and then next we have key to value two and then separated also by a comma from the

176
00:14:35,210 --> 00:14:37,060
rest and so on and so forth.

177
00:14:37,070 --> 00:14:44,060
So here you see we have this is key one here, key one, value one.

178
00:14:44,060 --> 00:14:52,850
We have the comma and then we have key to this headers, key two headers and then value to now value

179
00:14:52,850 --> 00:14:54,560
two years all this year.

180
00:14:54,560 --> 00:14:59,360
So all this data is of value to So all this.

181
00:14:59,790 --> 00:15:05,670
So our value to and then we have a comer just like yours.

182
00:15:05,670 --> 00:15:11,250
We had this comma and then after we have key three and then value three.

183
00:15:11,640 --> 00:15:18,300
Now for a particular value, we could also have some sort of dictionary.

184
00:15:18,480 --> 00:15:21,570
And so in this case, let's take all this off.

185
00:15:21,570 --> 00:15:28,470
In this case where we had this empty dictionary, this was quite simple, but here we have this dictionary

186
00:15:28,470 --> 00:15:31,730
field with its own key value pairs.

187
00:15:31,740 --> 00:15:35,280
So here we have this key and we have this value.

188
00:15:35,280 --> 00:15:40,620
And then this value is a dictionary made of its own key value pairs.

189
00:15:40,650 --> 00:15:43,650
So you have the commerce again and just like that.

190
00:15:43,650 --> 00:15:51,120
So you have the commas separating each and every key value pair and then you're you just have this string.

191
00:15:51,120 --> 00:15:57,810
So basically what we have in here is we have a key, which is a string.

192
00:15:58,620 --> 00:16:02,220
And we have a value, which is some variable.

193
00:16:02,220 --> 00:16:05,160
Now this variable can be a dictionary like this.

194
00:16:05,160 --> 00:16:11,490
The first two examples, or it can be a string, or it could be an integer or even a boolean.

195
00:16:11,760 --> 00:16:15,780
Now, if you check on this other request, here's the push request.

196
00:16:15,780 --> 00:16:18,420
You'll see this same formatting.

197
00:16:18,420 --> 00:16:23,310
So we have the curly braces which open and close, and then we have each key.

198
00:16:23,310 --> 00:16:25,530
And this value, the key is value.

199
00:16:25,560 --> 00:16:26,550
Key value.

200
00:16:26,550 --> 00:16:28,720
And finally, key value.

201
00:16:28,740 --> 00:16:30,870
Now, this was for the response.

202
00:16:30,870 --> 00:16:32,850
So this was the response body.

203
00:16:33,090 --> 00:16:38,070
Let's go ahead and check at the request body, request body.

204
00:16:38,070 --> 00:16:45,060
We had this form data, but actually we could have raw JSON data which is passed.

205
00:16:45,060 --> 00:16:53,280
So instead of using this, like basically using this UI, we could have this raw and then pass in JSON

206
00:16:53,280 --> 00:16:53,640
data.

207
00:16:53,640 --> 00:16:57,690
So it's here is actually very easy to to write this out.

208
00:16:57,840 --> 00:16:59,220
Let's have this here.

209
00:16:59,250 --> 00:17:01,560
Let's check back at the form data.

210
00:17:01,560 --> 00:17:03,720
We have email, password and job.

211
00:17:04,530 --> 00:17:08,010
Yeah, we have the same so we have email.

212
00:17:08,400 --> 00:17:09,360
There we go.

213
00:17:09,360 --> 00:17:17,970
We specify the email, learn the AI, and then we have the password.

214
00:17:18,480 --> 00:17:24,930
Our password is not a password, so not a password.

215
00:17:25,050 --> 00:17:26,040
There we go.

216
00:17:26,040 --> 00:17:27,690
Next and final one.

217
00:17:27,690 --> 00:17:29,040
We have the job.

218
00:17:29,040 --> 00:17:34,590
We have your new learns.

219
00:17:34,620 --> 00:17:35,970
Okay, so we have that.

220
00:17:35,970 --> 00:17:41,610
So notice how here we constructing this raw data, which we're going to pass in and we're going to see

221
00:17:41,610 --> 00:17:43,050
the output we get your.

222
00:17:43,050 --> 00:17:48,750
So let's send this and what do we get here is what we get as output.

223
00:17:48,750 --> 00:17:52,050
You see your unsupported major type text planning requests.

224
00:17:52,050 --> 00:17:59,100
So this means that the request we sent was text type and not the JSON format.

225
00:17:59,100 --> 00:18:03,990
So you'll notice here we have text which was selected and we just simply have to change this to JSON.

226
00:18:03,990 --> 00:18:08,130
So changing the suggestion, what do you notice is here a change in color?

227
00:18:08,130 --> 00:18:15,090
That is because this now knows that here are the keys which are in red and the values in blue takes

228
00:18:15,090 --> 00:18:18,150
it back to C turns back to all black.

229
00:18:18,180 --> 00:18:21,570
Let's get back to JSON and then rerun this.

230
00:18:21,570 --> 00:18:27,300
So we click on Sell On Send and let's see the output using pass error.

231
00:18:28,630 --> 00:18:29,940
We check that here.

232
00:18:29,970 --> 00:18:32,760
Let's take that off and then send again.

233
00:18:33,180 --> 00:18:33,590
Okay.

234
00:18:33,600 --> 00:18:38,910
So you see now that once we correct that and send this JSON data, we have this output.

235
00:18:38,910 --> 00:18:44,340
So basically using this form data right here, which you could now take off, let's take this off is

236
00:18:44,340 --> 00:18:47,660
the same as passing this raw JSON data.

237
00:18:47,670 --> 00:18:54,510
So the role of post mine is to make it easier for people to test their APIs using this kind of graphical

238
00:18:54,510 --> 00:18:55,320
user interface.

239
00:18:55,320 --> 00:19:02,970
But you could always actually do it by passing this raw JSON data, as you can see here.

240
00:19:03,600 --> 00:19:05,100
And so now you have the status.

241
00:19:05,100 --> 00:19:05,640
Okay?

242
00:19:05,640 --> 00:19:10,530
Whereas when we had this text, let's send so you could see the status, you see for one five unsupported

243
00:19:10,530 --> 00:19:15,510
media type, let's get back to JSON and send and that's what we have.

244
00:19:16,380 --> 00:19:23,220
You also notice again that the level of the headers, we have this JSON format, so the body, the output

245
00:19:23,220 --> 00:19:26,280
we have here is JSON data.

246
00:19:26,580 --> 00:19:33,090
Then instead of passing this, let's add in some random stuff here and click on send.

247
00:19:33,300 --> 00:19:34,350
What do we have?

248
00:19:34,350 --> 00:19:40,680
We have all four not found, but we'll notice that the content type that we have now is no longer the

249
00:19:40,680 --> 00:19:43,380
JSON, but instead HTML.

250
00:19:43,380 --> 00:19:48,690
And when you check out the body, you see we have this year preview page not found.

251
00:19:49,020 --> 00:19:54,960
This shows us that we can have different content types exchanged between the client and the server.
