MongoDB with Async Python Transcripts
Chapter: FastAPI Example
Lecture: The Home Page Doesn't Belong in the API Docs

Login or purchase this course to watch this video and the rest of the course contents.
0:00 There's two more really quick things that I want to do just to round this out, we could
0:05 call it done, we have our API pretty much working, don't wait, it's pretty awesome.
0:11 But I want to just do two real world things that you would do for FastAPI, I already
0:16 told you, right, we're going to kind of build this out proper, like with documentation,
0:21 which what we saw over here with our model response model integration into open API,
0:27 those sorts of things. Here's one though, Hello World, or if we named it, you know, something down here, just like index or home,
0:38 whatever you call it, and we refresh this, it'll get a slightly different name. But is this really part of our API documentation? No.
0:46 It's just here so that if we visit the site, we didn't get a 404, right?
0:53 We just got at least something here. Now, this is not a great response. We're gonna work on that.
0:57 But we got something that wasn't just a 404 not found until you managed to somehow type in the API endpoints. All right, but it shouldn't be here.
1:05 So let's exclude the parts of our site that either we want to just keep super duper private,
1:11 or for things like this that are really just about exchanging information for a user, a
1:17 human for a browser, not for an API call doesn't belong in the API documentation. Turns out, it's incredibly easy.
1:24 You go over here to this endpoint, this is the homepage, and a really, really loose definition of that. And you don't want to show up, you just say,
1:34 instead of response model, you say include in schema false. This is not part of my API. Don't think that it is, please. Run it again, refresh.
1:44 Better, there we go. We have our three endpoints over here in our open API, FastAPI documentation. And the thing that was really just there to support
1:56 normal use of a website, but it's not an API, is now gone. Just include in schema, false.


Talk Python's Mastodon Michael Kennedy's Mastodon