Placeholder Image

字幕列表 影片播放

  • Hello, everyone.

  • In today's video, we're gonna take a look at http status coat and going over all of the different codes that you need to know in order to develop Web applications and web AP eyes to the best of your ability.

  • Let's get started now.

  • So if you're unfamiliar with http status codes, essentially what they are, is there a way for the server to communicate with the browser in a really structured way so that both parties know exactly what's going on?

  • A really common code that you've probably seen before is the 404 air, which essentially means not found.

  • This happens.

  • If you try to go to a Web page that doesn't exist, the server is going to give you a 44 air saying that the page you're looking for does not exist.

  • And in order to go over all of the browser codes that you need to understand, http, codes I'm gonna pull the Web page here That's going to show all of the different available codes that you could think of.

  • And I'm gonna cover all of the ones you need to know and exactly what they mean.

  • So here I am on a site on a Web page called Rest A P i tutorials dot com.

  • I'm gonna link it down in description below for you to take a look at because it has really nice descriptions of all of these different status codes.

  • If you want to take a look and read in depth what each one actually means, but their specific status code that are much more important and more common than any of the other codes and those the ones I'm gonna cover in this video, the ones that you really need to know to develop a p i's and Web pages and I'm gonna go by the categories.

  • There's five different categories here we're gonna cover, which is 100 to 500.

  • And the starting category here is the 100 category, which is informational.

  • You don't need to know any of these.

  • Just pretend this category doesn't even exist.

  • You're never going to use them building web ap eyes or websites.

  • So just completely ignore this category and we're gonna move on to the 200 category, which is something you're gonna see all the time and essentially any code in the 200 category section means that the request you made was a good request.

  • It was successful.

  • It completed correctly.

  • It did what it was supposed to do.

  • And the very basic version just 200.

  • It just means okay, this is a very general status code which essentially says, Okay, this request came to us, it was successful.

  • I have nothing particular to say about it.

  • It was just a successful request.

  • So 200 is the most general success message.

  • You consent to people, and it's something you're going to see all of the time.

  • The next most common 200 code you're gonna see is the to a one status code.

  • And if you're building a rest, A P I, for example, all of your post request to create resource is, for example, create user create item, create shopping cart, whatever it is when you create something on a P I you want to return a two a one status code which essentially says created It just means you created some resource and it was successful.

  • You could return a 200 status coat and technically, that would be okay because they both mean okay, but sending a two a one gives the browser just a little bit more information so that they know that you actually created something.

  • And it wasn't just a general success message.

  • The idea of the status code is to give his much information to the browser as possible without actually having to do too much work.

  • Because the status code do the work for you.

  • Another really popular status code is 204 and the two of four status code essentially means that you something went well.

  • Everything worked as expected, but you have nothing to return.

  • A lot of times, if you have a delete request to an A P I and you want to delete a user, you don't have to return anything from the A.

  • P.

  • I call the a pie server is not gonna give you information back because you just sent them an idea to delete and they deleted it.

  • So they're going to send you back a 204 and this two of four essentially says we did what you wanted us to do it once successful, and we have nothing to give back to you.

  • So while the Times, if you don't return to a four and you just return a 200 the browser or the person consuming your A P.

  • I might get confused because those say, OK, you gave me a good successful message, but you gave me nothing.

  • In return, something must be broken.

  • But with this two of four status code, what you're telling the person using your a p I is We're not sending you anything, But that's okay.

  • We aren't expecting to send you anything.

  • Sending you nothing is exactly what we want to do.

  • The next category of codes that we want to talk about are the 300 level status codes and these handle if you want to redirect the user.

  • So if someone goes to, for example, some website and that web page jorelys redirecting himto another web page, you are Oh, you're gonna get a 300 status code from the first girl that you go to, which is essentially saying, Hey, this Web page used to be here, But now it's over here.

  • There's a bunch of different codes to indicate different levels of redirection.

  • But the main one that you want to know is this 304 And this actually isn't so much about redirecting the user from one euro to another.

  • This is actually doing with cashing information.

  • And so when you're calling in a P, I, maybe you don't want to get all the results every time because they don't change that often.

  • Maybe they change every couple of days, but you want to query it constantly, just in case something changes.

  • You want to be updated immediately, so you can do is when you're calling that a P I.

  • You send it up a message that says, Has this been changed since X Date?

  • Since yesterday, for example, and if it has not been changed since yesterday, the server sends back this three or four status, which says no, nothing has changed since yesterday.

  • Don't even worry about it.

  • And then that way the server doesn't have to send you any extra information.

  • You don't have to download extra information.

  • No extra work needs to be done because it's server says no.

  • Nothing has changed since that date.

  • But if, for example, the server information has changed since then, instead of sending you this three or four, their most likely gonna send you some 200 level status, and they're gonna give you the information that you're looking for.

  • So the idea of this three or four is just a way to save bandwidth, essentially, instead of having to download everything every time to check if it's changed, the server will just tell you it hasn't changed and it won't give you anything.

  • It'll just say, pull it from the cash that you have now that's all you really need to know about the 300 level errors.

  • So we're gonna move on to the 400 level section and there's a bunch that you need to know in the 400 level section.

  • AA 400 level error is essentially an error from the client side.

  • So the person using your A p I sent you either bad information.

  • They are authorized something along the lines of what the user sent you was bad, which is different than 500 level errors, which is when something broke on the server.

  • So everything the user sent you was correct.

  • But the server itself that's running the AP I had some kind of air, maybe the databases down.

  • Maybe some kind of exception was thrown.

  • That would be a 500 level air, and we're gonna first focus on the 400 level errors because there's much more of them that you're going to return.

  • And the 1st 1 is just the basic 400 air.

  • This is just a general air that says something went wrong.

  • Something happened.

  • Your information was bad, and I'm telling you, it's bad by sending you a 400.

  • Generally, you only really use 400 errors when you don't know the specific reason for something being bad.

  • Or maybe the user just sent you bad parameters.

  • So, for example, if you want to create a new user and you need to pass a name and an email and the client that's using the AP, I only sent the name.

  • They didn't send you the email, so that's a bad request.

  • You send them back that 400 air saying you didn't give me all the information I need because the name and email required.

  • So you send a 400 air.

  • The other two common types of errors that you're going to see here is the for a one and the 403 thes air.

  • Very, very similar.

  • There's unauthorized and then forbidden.

  • Ah 401 which is the unauthorized air essentially means you're trying to access something that requires some form of authentication.

  • You must be logged in or you need a P I ke something like that.

  • But you didn't pass it or the one you passed was just incorrect.

  • The server didn't know what you meant.

  • So if you need an a p I key to access the FBI and you never send in a p i ke the server is going to respond with a 401 sane I don't know who you are.

  • You didn't give me an a p i ke you need to give me an A P i ke but of four or three would happen if the client sent in a p i ke.

  • But the service that they're accessing requires different permissions.

  • Let's say that they're just a basic user and they tried to access an admin feature in the A P I.

  • The server would give them a 403 which just says I know who you are, but you do not have permission to access this.

  • So I'm going to say you're forbidden from this with a 403 You cannot access this.

  • You need to have better credentials, admin credentials to access this section of the application as kind of the difference between 401 and 40341 says, I have no idea who you are.

  • And 403 is saying I know who you are, but you cannot access this.

  • So go away.

  • The other types of areas that you're gonna see in the 400 section is gonna be namely the 404 error, which is not found.

  • This is the one I talked about at the beginning of the video.

  • This just says that you're accessing some part of that Web application you're trying to, at least, but that part does not exist.

  • For example, if you have an application that has a user's a p I, and someone tries to access a shopping cart, a p i inside of it, there is no shopping cart, a p I.

  • So the server just says I don't know what you want.

  • We don't have this.

  • So here's a 44 I can't find what you're looking for.

  • And those were really the main 400 double ares that you're gonna be running into when it comes to 500 level Ares.

  • The really only one that you're gonna worry about is this 500 air here just the very generic 500 air, which is just saying something broke on the server.

  • Usually, when you have a problem with the server, it's a problem that you don't expect.

  • For example, your code has a bug in it and it throws an heir or your database is down.

  • For some reason, it's not something you can really program around.

  • So in general when you throw a 500 error, it's because something bad happened that you did not expect to happen.

  • So you're saying I don't know what happened?

  • The servers broken.

  • Here's a 500 error and the reason you send a 500 error when the server is broken.

  • And so the person using the FBI knows that what they're doing is not wrong, because if they keep sending up request and they keep getting 400 errors back, they'll think something with their code is wrong.

  • When in actuality, if the server is broken, you need to send a 500.

  • So the user knows.

  • Okay, the server is broken.

  • It's not my fault.

  • It's their fault.

  • Hopefully they'll get it fixed for me.

  • And that's all the basic, http status codes you need to know.

  • Like I said, I'm gonna link that site in the description below.

  • If you want to check out all of the other codes I didn't cover.

  • But for all intensive purposes, those codes I covered a really old the codes that you're ever gonna run across one building ap eyes.

  • And if you enjoy that video, make sure you subscribe to my channel and click the videos over here, which is somewhere to this video.

  • Thank you very much for washing and have a good day.

Hello, everyone.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

10分鐘內學會HTTP狀態碼 (Learn HTTP Status Codes In 10 Minutes)

  • 1 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字