Response
Last updated
Last updated
The previous module made several mentions of an HTTP "response". Let's take a closer look at this concept.
We most often see HTTP responses as status codes. These are three digit numbers that give us an indication if our code is doing what we want. Before we look at specific examples, let's discuss the five categories of status codes, as defined by their first digit.
Value
Category
Explanation
1xx
Informational
Request received; continuing process
2xx
Success
The action was successfully received, understood, and accepted
3xx
Redirection
Further action must be taken in order to complete the request
4xx
Client Error
The request contains bad syntax or cannot be fulfilled
5xx
Server Error
The server failed to fulfill an apparently valid request
Let's talk about some of the most common HTTP Status Codes. To better illustrate their meanings, we'll use some awesome and .
404 - Not Found
The dreaded 404 occurs when the server is unable to find what you are looking for, typically an HTML page.
404s are most often the result of broken or dead links, meaning the information you are looking for has either been moved or removed completely.
One way to troubleshoot a 404 is to make sure you have input the URL correctly without any typos.
401 - Unauthorized
401 errors often occur because a user needs to enter valid credentials to view a particular page.
Make sure you have permission to access the page in question and enter a proper username/password.
This error is similar to 403 - Forbidden.
400 - Bad Request
400 errors often are due to syntax errors in the code or some other problem with the request on the client side.
500 - Internal Server Error
500 is a generic message that is thrown when a unexpected error occurs.
Yeah, I know. great help.
It's important to know that this an error on the SERVER side, so nothing to do with the client.
502 - Bad Gateway
A 502 code means that the server sent a valid request, but somewhere another server returned an invalid response.
Most requests are routed through a number of servers. Think of christmas tree lights; if one light fails, the remaining lights all fail.
418 - I'm a Teapot
The most dangerous error to ever receive. Pray that you never encounter it.
Jk, it's actually an April Fool's joke from 1998 and is an inside joke among the industry.
If you click on one of the requests, you will see more information about that specific code. For the moment, just remember about this feature. As you work more with APIs, you will utilize the network tab more heavily. For now, focus on the status code, and know that if you need to you can look more in-depth at each request.
Remember, data from these responses is passed with minified JSON.
So it's nice to know that these status codes exist for responses from the API, but how can you actually see these? The answer is in your browser. Open up chrome, and go to . Open up the inspector (right-click on the page and select inspect), and then navigate to the network tab. With the network tab open, refresh the page. You should see a bunch of network requests populate the tab. Most of these have a status of 200 or OK, meaning that the requests were good. Feel free to play around with this on websites you usually frequent.