Modern APIs with FastAPI and Python Transcripts
Chapter: Building our first API
Lecture: Know your HTTP status codes

Login or purchase this course to watch this video and the rest of the course contents.
0:00 http verbs are what the client is instructing the server to do and telling what the
0:04 server to do. But the server has an ability to talk back to the clients
0:08 say "yes, that worked" or "no,
0:10 that wasn't okay because of this",
0:12 or "you don't have permission". So the way the server communicates
0:14 that is with http status codes.
0:16 So if you are not super up on your http status codes,
0:20 you're gonna need to really get those a few of those figured out to
0:23 see exactly what you should tell all of your clients.
0:26 So a really good place to go is "httpstatuses.com" statuses not status.
0:31 There we go, http status codes.
0:34 Now, This is a really cool site because it doesn't just have them grouped and
0:38 categorized, but it has details.
0:39 So before you saw we got a 200
0:42 OK when we did a request for our calculate.
0:44 If you click on this, you get all sorts of information about when you should
0:48 do that, how you should do it
0:49 okay, so get represents, it's a good thing to return for a get If
0:53 here's a proper representation. The payload sends a 200 response.
0:57 It depends on the request method.
0:59 The meaning is basically "that worked" or this is the same as get but no data
1:04 and so on. Now, if you come down here,
1:06 you can even see, like,
1:07 some of the places you might use it.
1:09 There's like constants in Python, like "http.HTTPstatus.OK"
1:14 And you can use those if you like.
1:15 You can also come down here and we could see created.
1:17 This is much more common for a http post.
1:20 You know, once you've done a post like hey,
1:22 that worked, I created it,
1:23 And then you're going to say where it was. So all the 200's, these are
1:27 good. Over in the 400 section is another place where you definitely wanna look. So bad
1:31 request. Bad request is awesome because it means you passed some data, like invalid data,
1:37 or some other thing that's not good,
1:39 so we're not going to process that. We come down here and say "you don't have permission
1:43 to do it", or "this data was unacceptable",
1:47 so on. And then finally, the ones we hope we don't see too much of
1:50 are the 500 internal server errors.
1:53 So this is like the server crashed or some part of our infrastructure couldn't get to
1:59 another part, NGINX Couldn't talk to Gunicorn,
2:01 one of those types of things. Definitely
2:03 look through here when you're thinking about what should I send back
2:06 to answer this request, especially if there's something that went wrong.
2:09 What should I send back?
2:11 "httpstatuses" is a great place to go Look.