Full Web Apps with FastAPI Transcripts
Chapter: View models and services
Lecture: View models and Services Introduced

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

Talk Python's Mastodon Michael Kennedy's Mastodon