Full Web Apps with FastAPI Transcripts
Chapter: View models and services
Lecture: View models and Services Introduced
0:00 Our web application has come really far.
0:02 If you look at the design,
0:03 it looks a lot like the PyPI that we're looking to build.
0:06 We don't have our real data coming from the database yet.
0:09 We're getting there soon, but if we had that in place,
0:12 it would be quite close. However,
0:14 there's a few things that I would like to touch on before we get there, that
0:17 are going to help tremendously as our web application grows.
0:21 So there's two core design patterns or concepts that we're going to go through and integrate
0:26 into our PyPI clone during this chapter.
0:29 One is called "View Models". Now "View Models" are curious when we're working with FastAPI
0:34 They make perfect sense with Flask or Pyramid
0:37 where there's no natural exchange mechanism between the HTML data and the view processing and sending
0:44 that data back and forth between that template.
0:47 But in FastAPI, we have Pydantic.
0:49 So we're gonna talk about how "View Models" and Pydantic should coexist, when to use
0:55 one, when do you use the other.
0:57 Because you might think you can just use Pydantic models and to a degree,
1:00 you can, but they're not nearly as advantageous as what we will get with working with
1:05 view models, as we'll see.
1:07 Also, we're gonna talk about services. These are
1:09 not web services or APIs but just things that provide group functionality to
1:14 our application. So there'll be a "package service" that lets us do all the database
1:18 queries and processing and answer questions around packages.
1:21 Similarly for users, if this was a real app,
1:24 maybe we would have something that worked with email and it would figure out how do
1:27 we resend a reset email?
1:29 Or how do we load up templates and then pass that up and things like that.
1:33 So the are two patterns we're gonna talk about: "View Models" and "Services".
1:36 And we're also going to compare that with Pydantic as well.
1:38 And you're going to see, we're gonna be in a really good place with our web app after this chapter.