Anvil: Web apps with nothing but Python Transcripts
Chapter: Adding APIs and HTTP Endpoints
Lecture: Why APIs?
0:00 In this chapter
0:01 we're going to see how to build HTTP end points
0:03 and JSON based API's with our info application.
0:07 A good question that you might have
0:09 is why would I build an API?
0:11 So let's talk about the power of API's really quick.
0:14 Well, imagine we've got our web app running
0:17 in Anvil up in well, their servers.
0:19 But you know, maybe we consider our server
0:21 It's got a web app
0:22 It's got a database service, the data tables
0:24 all that stuff is over there.
0:26 And how do people work with it?
0:27 Well, they open up their web browser
0:30 either on a PC or on a mobile device
0:33 some kind of phone, and they request the page
0:36 and that's what we built so far.
0:38 They can interact with it, it has the graphs, it has the ad measurement
0:41 the login, all that stuff.
0:42 It's super, but this is only one part of the world.
0:46 It's the most invisible part to be sure
0:48 but it's not the only one
0:49 and not necessarily the most important.
0:52 We might also want to build a really sweet native app
0:56 that we sell through the App Store for iOS or Android.
0:59 And we We'd like to talk to the same data
1:01 basically have a native app version of the website
1:05 that people are going to use.
1:06 How does that talk to our server?
1:08 Well, it's definitely
1:09 not going to just request the same pages.
1:11 I need data in a computer readable format
1:13 like JSON or XML or something else, but not HTML.
1:17 Also, maybe some other websites or services
1:21 want to integrate with ours
1:22 maybe there's some healthcare company
1:24 and they have like a wellness program for their people.
1:27 And they would like to have all the customers of fitness
1:30 have their data integrated in
1:33 so to it automatically records this stuff
1:35 into their system as well.
1:37 If we want to make this happen
1:38 well, of course, we've got to build some API's
1:40 to allow that to happen.
1:42 Now another really powerful reason for API's
1:44 is to break up our app into smaller pieces.
1:47 This doesn't really make a lot of sense for envelopes.
1:50 But when you hear people talk about micro services
1:52 these are maybe a little web app that does authentication
1:55 one that compares measurements
1:56 one that's graph-some, things like that.
1:58 These are obviously connected with API's as well.
2:02 like I said, probably not a use case for anvil
2:04 But certainly a use case for API's.
2:06 So API's are super important
2:08 they connect all these things that make our apps
2:11 more amazing, make the integrations work
2:12 make architectural decisions more flexible.
2:17 But we're going to see how to build API's that are HTTP based
2:20 and sort of JSON in anvil.
2:23 It's easy as you can expect.