#100DaysOfWeb in Python Transcripts
Chapter: Days 21-24: Async Flask APIs with Quart
Lecture: Concept: Quart
0:00 So you now know async and await
0:02 we spend a little bit of time on the first day
0:04 in the first set of lectures talking about that.
0:07 How we can take regular code and make it async.
0:10 Here we have a function and we're converting it to
0:12 an asynchronous function by adding the async keyword
0:16 in front of def.
0:17 Any time that we're in a waiting state, any time we're
0:21 waiting for a response on calling a database or web search
0:25 or even getting something from a queue, cause maybe
0:27 the queue is empty or we're waiting until something
0:29 goes into in, who know how long that's going to take?
0:32 We need to await that so we're going to await any other
0:35 other calls to other asynchronous methods like this
0:38 asyncio queue.get.
0:41 It's async so we basically have to do this.
0:45 If you don't know whether it's async just go to
0:47 the definition of get, it says async def get, well you
0:50 should await it.
0:51 If it doesn't then you can't await it, I noticed also that
0:55 we're using data structures like the asyncio queue
0:58 to make this possible.
1:00 Right, so you know async and await now that we talked about
1:03 it in the first bit you already knew Flask, what do we do
1:06 to make Flask work?
1:08 Well, we add a route, we write our controller logic
1:12 and once we've come up with the data, we can either return
1:15 it as a JSON response or we can return it as a template
1:18 using that data, but we're going to return some response
1:22 back to the server by passing it as a model data.
1:25 You've already learned Flask, so you know asyncio as of
1:28 a day ago, you know Flask so putting that together to make
1:32 Quart, that's crazy easy right.
1:35 Now we convert our view method or our controller method into
1:39 async contoller method by adding async.
1:42 We implement our controller logic, but now awaiting any
1:46 chance that we can get the more asynchronous we can
1:49 make this, the better chance we have for scalability here.
1:52 And then we return our response, and notice anywhere we have
1:56 the word Flask we put Quart.
1:59 So this is really simple path forward, to go from a Flask
2:03 API to a asnycio friendly API, very cool.