1
00:00:02,020 --> 00:00:03,150
Now in this lecture,

2
00:00:03,150 --> 00:00:05,490
let me briefly come back to the question

3
00:00:05,490 --> 00:00:09,040
when you should build an API or a web service,

4
00:00:09,040 --> 00:00:11,210
and I'll use these terms interchangeably here

5
00:00:11,210 --> 00:00:14,170
because when I say API here in this lecture,

6
00:00:14,170 --> 00:00:17,290
I mean a URL-based API.

7
00:00:17,290 --> 00:00:21,489
So in the end, the web service where we expose various URLs

8
00:00:21,489 --> 00:00:24,830
to which other developers, other people can send requests

9
00:00:24,830 --> 00:00:27,550
and where the main goal of these URLs

10
00:00:27,550 --> 00:00:31,220
is to then return data, not HTML pages.

11
00:00:31,220 --> 00:00:33,540
Of course, you probably already have an idea

12
00:00:33,540 --> 00:00:36,670
of when you might wanna build such an API.

13
00:00:36,670 --> 00:00:40,020
For example, if you're building an alternative to Stripe,

14
00:00:40,020 --> 00:00:42,030
if you're building your own payment service

15
00:00:42,030 --> 00:00:44,570
and you wanna expose that to the world,

16
00:00:44,570 --> 00:00:48,040
but there also are other reasons and to understand those,

17
00:00:48,040 --> 00:00:49,720
let's take a step back

18
00:00:49,720 --> 00:00:53,050
and let's understand when a classic website

19
00:00:53,050 --> 00:00:54,840
makes most sense.

20
00:00:54,840 --> 00:00:56,610
So a website as we built it

21
00:00:56,610 --> 00:00:59,010
multiple times throughout this course

22
00:00:59,010 --> 00:01:01,750
where you have your views on the backend

23
00:01:01,750 --> 00:01:05,150
and where it's all about returning HTML code

24
00:01:05,150 --> 00:01:07,127
to the requester because the requester

25
00:01:07,127 --> 00:01:10,200
typically is the browser where a user,

26
00:01:10,200 --> 00:01:11,710
a visitor of your site,

27
00:01:11,710 --> 00:01:14,463
entered some URL or clicked some link.

28
00:01:15,470 --> 00:01:17,660
Now, such a website makes a lot of sense

29
00:01:17,660 --> 00:01:21,460
if you want people to, well, view your website

30
00:01:21,460 --> 00:01:24,960
and when your main product is the website itself.

31
00:01:24,960 --> 00:01:28,430
So for example, if you're building a blog or an online shop,

32
00:01:28,430 --> 00:01:32,150
then of course your website is the main product.

33
00:01:32,150 --> 00:01:34,940
The online shop we built before in this course

34
00:01:34,940 --> 00:01:36,800
is the product itself.

35
00:01:36,800 --> 00:01:39,770
We would earn money by having that shop

36
00:01:39,770 --> 00:01:42,560
where people can then buy something.

37
00:01:42,560 --> 00:01:43,480
So in such a case,

38
00:01:43,480 --> 00:01:46,460
such a traditional website makes a lot of sense

39
00:01:46,460 --> 00:01:50,790
because we have this tight coupling of frontend and backend,

40
00:01:50,790 --> 00:01:53,640
and we wanna render those dynamic pages,

41
00:01:53,640 --> 00:01:55,350
which contain our products

42
00:01:55,350 --> 00:01:59,253
or some user-specific data like cart and so on.

43
00:02:00,400 --> 00:02:04,010
Now, when it comes to building a web API or web service,

44
00:02:04,010 --> 00:02:05,810
then of course we have the case

45
00:02:05,810 --> 00:02:08,539
that we wanna build something like Stripe.

46
00:02:08,539 --> 00:02:10,520
Let's say Stripe doesn't exist yet

47
00:02:10,520 --> 00:02:13,630
and we have the idea that such a service,

48
00:02:13,630 --> 00:02:15,100
which other people can use,

49
00:02:15,100 --> 00:02:19,080
where we help them handle payments would be a great idea.

50
00:02:19,080 --> 00:02:21,510
We could then build such a service.

51
00:02:21,510 --> 00:02:24,010
But there also is an alternative use case

52
00:02:24,010 --> 00:02:26,490
which we haven't explored thus far

53
00:02:26,490 --> 00:02:30,620
and that use case would be that we mostly wanna expose

54
00:02:30,620 --> 00:02:33,030
some data in the end,

55
00:02:33,030 --> 00:02:36,750
some data that can then be consumed from different clients

56
00:02:36,750 --> 00:02:38,760
and I'll come back to this.

57
00:02:38,760 --> 00:02:40,370
Now, the left case here,

58
00:02:40,370 --> 00:02:43,240
building a web service like Stripe should be clear.

59
00:02:43,240 --> 00:02:46,570
We have the goal of giving our developers,

60
00:02:46,570 --> 00:02:49,170
customers access to this API.

61
00:02:49,170 --> 00:02:51,440
Probably we will charge them for that,

62
00:02:51,440 --> 00:02:53,890
but then they can use our service or API

63
00:02:53,890 --> 00:02:55,990
to integrate it into their own products,

64
00:02:55,990 --> 00:02:58,223
into their own sites or APIs.

65
00:02:59,150 --> 00:03:02,570
Of course, we could also use such a service on our own.

66
00:03:02,570 --> 00:03:06,450
If we are Stripe, we could use our ourselves,

67
00:03:06,450 --> 00:03:10,020
we could use our own service in some other product

68
00:03:10,020 --> 00:03:12,130
which might need payments

69
00:03:12,130 --> 00:03:15,160
to offer some other service to end customers.

70
00:03:15,160 --> 00:03:16,800
This, of course, would be possible.

71
00:03:16,800 --> 00:03:20,910
We can become a customer of ourselves in this case,

72
00:03:20,910 --> 00:03:22,693
probably without paying though.

73
00:03:23,790 --> 00:03:26,200
Now, the right case is interesting though.

74
00:03:26,200 --> 00:03:28,900
Of course, the borders are always kind of blurry,

75
00:03:28,900 --> 00:03:30,790
but we could be building an API,

76
00:03:30,790 --> 00:03:33,910
as we will do it throughout this course section,

77
00:03:33,910 --> 00:03:36,760
where we don't necessarily offer a service

78
00:03:36,760 --> 00:03:40,120
that is super useful to a lot of other developers.

79
00:03:40,120 --> 00:03:43,490
Instead, we could build an API which offers, for example,

80
00:03:43,490 --> 00:03:48,040
all these CRUD operations, create, read, update, and delete,

81
00:03:48,040 --> 00:03:51,250
for managing to-do's or anything like this.

82
00:03:51,250 --> 00:03:54,060
And then we could plan to use this ourselves,

83
00:03:54,060 --> 00:03:57,750
but we might have different user-facing clients

84
00:03:57,750 --> 00:04:00,490
that should be connected to this API.

85
00:04:00,490 --> 00:04:05,120
And with user-facing clients, I mean things like browsers,

86
00:04:05,120 --> 00:04:07,910
so a decoupled web frontend let's say,

87
00:04:07,910 --> 00:04:11,490
so a static page in the end with no backend code

88
00:04:11,490 --> 00:04:13,700
that might run on a different server,

89
00:04:13,700 --> 00:04:16,660
but which uses Ajax to talk to our API,

90
00:04:16,660 --> 00:04:19,820
to fetch data, send data and so on,

91
00:04:19,820 --> 00:04:21,279
but also other clients,

92
00:04:21,279 --> 00:04:24,083
like for example desktop or mobile apps.

93
00:04:25,070 --> 00:04:27,990
Of course, we could be building a mobile app,

94
00:04:27,990 --> 00:04:32,310
which lets users manage their daily to do's let's say,

95
00:04:32,310 --> 00:04:37,280
and that mobile app would need to talk to some server

96
00:04:37,280 --> 00:04:39,590
because we might not wanna store those to-do's

97
00:04:39,590 --> 00:04:41,560
just on the user's device.

98
00:04:41,560 --> 00:04:43,210
If the user switches the device,

99
00:04:43,210 --> 00:04:45,030
all the to-do's would be gone.

100
00:04:45,030 --> 00:04:47,090
We might wanna store them on our server

101
00:04:47,090 --> 00:04:48,723
and our database instead.

102
00:04:49,630 --> 00:04:52,610
Therefore, we need a server and we need a database,

103
00:04:52,610 --> 00:04:57,060
but what we don't need in that case is HTML code and views.

104
00:04:57,060 --> 00:04:59,150
Because if we're building a mobile app,

105
00:04:59,150 --> 00:05:01,480
it turns out that those mobile apps

106
00:05:01,480 --> 00:05:03,990
don't want HTML responses.

107
00:05:03,990 --> 00:05:06,410
Instead, there you build the user interface

108
00:05:06,410 --> 00:05:08,913
with totally different programming languages.

109
00:05:10,310 --> 00:05:12,890
There is a reason why there are dedicated courses

110
00:05:12,890 --> 00:05:15,390
teaching you mobile app development.

111
00:05:15,390 --> 00:05:18,470
You build user interfaces with other tools there

112
00:05:18,470 --> 00:05:23,113
with other languages, not necessarily with HTML and so on.

113
00:05:24,470 --> 00:05:27,140
Therefore, such a mobile app might want the data,

114
00:05:27,140 --> 00:05:30,530
but not the views, not the HTML code.

115
00:05:30,530 --> 00:05:32,780
And that would be another use case.

116
00:05:32,780 --> 00:05:36,110
We might not be building a service that's super useful

117
00:05:36,110 --> 00:05:38,110
to a lot of other people in the world,

118
00:05:38,110 --> 00:05:40,680
to a lot of other companies that should use it,

119
00:05:40,680 --> 00:05:42,770
but instead we might be building an API

120
00:05:42,770 --> 00:05:46,010
that's pretty much only useful to ourselves,

121
00:05:46,010 --> 00:05:48,970
but we don't plan on just building a website.

122
00:05:48,970 --> 00:05:51,350
Instead, we might wanna build such a mobile app

123
00:05:51,350 --> 00:05:53,900
and therefore we don't need the frontend part.

124
00:05:53,900 --> 00:05:55,410
We don't need the views.

125
00:05:55,410 --> 00:05:58,970
We just want an API to which our mobile app can talk

126
00:05:58,970 --> 00:06:01,130
so that it can fetch data from there

127
00:06:01,130 --> 00:06:05,100
and then display it in its native user interface.

128
00:06:05,100 --> 00:06:07,540
And this is also a common use case

129
00:06:07,540 --> 00:06:09,790
that you need a backend, but not a frontend,

130
00:06:09,790 --> 00:06:12,610
because your frontend might not be a website,

131
00:06:12,610 --> 00:06:15,393
but instead a mobile app or desktop app.

132
00:06:16,370 --> 00:06:18,920
Now still, it could also be a frontend.

133
00:06:18,920 --> 00:06:21,130
It would also be very common

134
00:06:21,130 --> 00:06:23,370
that you have different clients,

135
00:06:23,370 --> 00:06:27,750
let's say browsers and mobile apps talking to the same API

136
00:06:27,750 --> 00:06:31,620
because you might wanna have users on mobile devices

137
00:06:31,620 --> 00:06:35,090
and users who visit your website through a browser.

138
00:06:35,090 --> 00:06:36,960
This is also quite common.

139
00:06:36,960 --> 00:06:40,130
If you think about Facebook or Google Maps

140
00:06:40,130 --> 00:06:44,780
or basically any big company, you can visit their offerings,

141
00:06:44,780 --> 00:06:47,340
you can visit Facebook through the browser

142
00:06:47,340 --> 00:06:49,030
on your desktop device

143
00:06:49,030 --> 00:06:52,000
or you can visit it through their mobile app.

144
00:06:52,000 --> 00:06:55,940
And there, it is the case that the frontend on the browser

145
00:06:55,940 --> 00:06:57,230
and the mobile app,

146
00:06:57,230 --> 00:07:00,700
that these two are two totally different clients in the end,

147
00:07:00,700 --> 00:07:04,600
but they probably talk to the same Facebook API

148
00:07:04,600 --> 00:07:07,173
somewhere on some Facebook servers.

149
00:07:08,240 --> 00:07:10,000
So that's also a use case.

150
00:07:10,000 --> 00:07:11,900
And with this course section

151
00:07:11,900 --> 00:07:14,670
and the overall knowledge you gained throughout this course,

152
00:07:14,670 --> 00:07:17,700
you will be able to handle all these scenarios

153
00:07:17,700 --> 00:07:20,090
and all these use cases.

154
00:07:20,090 --> 00:07:21,840
So therefore, that was a lot of talking,

155
00:07:21,840 --> 00:07:23,180
but now it's hopefully clear

156
00:07:23,180 --> 00:07:25,280
why you might wanna build such APIs

157
00:07:25,280 --> 00:07:28,300
and what possible use cases are.

158
00:07:28,300 --> 00:07:30,110
Now, we're going to see this right case,

159
00:07:30,110 --> 00:07:33,920
this data API case in action throughout this course section,

160
00:07:33,920 --> 00:07:35,850
and therefore let's not waste any time

161
00:07:35,850 --> 00:07:37,293
and instead dive right in.

