#100DaysOfWeb in Python Transcripts
Chapter: Days 9-12: FastAPI
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 server to do.
0:06
But the server has an ability to talk back to the client and say, yes, that worked, or
0:11
no, that wasn't okay, because of this, or you don't have permission. So the way the server communicates that is with HTTP status codes.
0:18
So if you are not super up on your HTTP status codes, you're going to need to really get
0:23
those a few of those figured out to see exactly what you should tell all of your clients. So a really good place to go is HTTP statuses.com.
0:32
Status is not status, there we go. It should be status codes. Now this is a really cool site because it doesn't just have them grouped and categorized,
0:40
but it has details. So before you saw we got a 200 okay, when we did a request for our calculate, if you
0:46
click on this, you get all sorts of information about when you should do that, how you should do it.
0:51
Okay, so get represents, it's a good thing to return for a get if here's a proper representation, the payload sends a 200 response.
0:59
And it depends on the request method. The meaning is basically that worked, or this is the same as get but no data and so on.
1:06
Now if you come down here, you can even see like some of the places you might use it. There's like constants in Python, like HTTP.httpstatus.okay.
1:15
And you can use those if you like. You can also come down here and we can see created. This is much more common for HTTP post.
1:21
You know, once you've done a post like, hey, that worked, I created it. And then you're going to say where it was. All the 200s, these are good.
1:29
Over in the 400 section is another place where you definitely want to look so bad request
1:33
about request is awesome, because it means you pass some data like invalid data or some other thing that's not good.
1:40
So we're not going to process that. We come around here and say you don't have permission to do it. Or this data wasn't acceptable. So on.
1:50
And then finally, the ones we hope we don't see too much of are the 500 internal server errors.
1:54
So this is like the server crashed or some part of our infrastructure couldn't get to another part.
2:01
Nginx couldn't talk to unicorn, one of those types of things.
2:04
Definitely look through here when you're thinking about what should I send back to answer this
2:08
request, especially if there's something that went wrong. What should I send back? HTTP statuses is a great place to go look.