Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 5

Understanding HTTP Status Codes

Recommended resources

Hello! Welcome to the fifth lesson in our module on "How the Web Works."

Introduction

In our last lesson, you learned about the four main HTTP methods: GET, POST, PUT, and DELETE. You now know how to tell a server what action you want to perform on a resource. For example, you can ask to GET a list of products or POST a new user.

But communication is a two-way street. After you make a request, how does the server tell you if it was successful? What if the resource you asked for doesn't exist, or you don't have permission to access it?

This is where HTTP status codes come in. They are the server's way of replying to your request, giving you immediate feedback on the outcome.

In this lesson, you will learn to interpret the most common HTTP status codes. We will focus on the three most important families of codes you'll encounter when working with APIs:

  • 2xx (Success)
  • 4xx (Client Errors)
  • 5xx (Server Errors)

Understanding these codes is a critical skill for debugging your code and building reliable applications.


What are HTTP Status Codes?

Every time a server responds to an HTTP request, it includes a three-digit status code in the response. Think of it like a traffic signal for your request:

  • ✅ 2xx codes are like a green light: Your request was received, understood, and processed successfully.
  • ❌ 4xx codes are like a red light because of a mistake you made: There was something wrong with your request. Maybe you typed the URL incorrectly or didn't provide the right credentials. The problem is on the client's side (your side).
  • 💥 5xx codes are also like a red light, but because of a problem on the other end: Your request was perfectly valid, but the server failed to process it. The problem is on the server's side.

While there are other families of codes (1xx for information and 3xx for redirection), the 2xx, 4xx, and 5xx families are the ones you'll see most often when building and using APIs.

To get a clear overview of the most essential codes, please watch the following video.

Learn HTTP Status Codes In 10 Minutes

The video 'Learn HTTP Status Codes In 10 Minutes' from Web Dev Simplified provides a concise and clear explanation of the most important status codes you'll need to know as a developer.

Watch the video from the beginning until 10:02. Pay close attention to: The difference between a success (2xx), a client error (4xx), and a server error (5xx). The specific meaning of codes like 200, 201, 404, and 500.


Deconstructing the Codes

The video gave you a great tour of the most common status codes. Let's recap and organize them so they're easy to remember.

✅ 2xx Success Codes: "We got it, and it worked!"

This family of codes means the server successfully processed your request.

  • 200 OK: The all-purpose success code. It's the standard response for successful GET and PUT requests. It means "everything is fine."
  • 201 Created: This is more specific than 200. It means a new resource has been successfully created as a result of your request. You'll typically see this after a successful POST request (e.g., creating a new user).
  • 204 No Content: This code means the server successfully processed your request but has no data to send back in the response body. This is a common response for a successful DELETE request. The server is telling you, "I deleted it, and that's all there is to say."

❌ 4xx Client Error Codes: "You made a mistake."

This family indicates that the request sent by the client was flawed in some way. When you see a 4xx error, the first place to look for a fix is in your own code.

  • 400 Bad Request: This is a generic client-side error. It means the server couldn't understand your request because it was malformed. A common cause is sending invalid data, like a JSON object that's missing a required field.
  • 401 Unauthorized: You are not authenticated. The server doesn't know who you are. This means you need to provide valid credentials (like an API key or a username/password) to access the resource.
  • 403 Forbidden: The server knows who you are, but you don't have permission to access this resource. This is different from 401. With 403, you are successfully logged in, but your user role (e.g., 'viewer') doesn't allow you to perform the requested action (e.g., 'delete a file').
  • 404 Not Found: This is one of the most famous codes. It simply means the server could not find the resource at the URL you requested. You either mistyped the URL or are trying to access an endpoint that doesn't exist.

💥 5xx Server Error Codes: "We made a mistake."

This family means that your request was valid, but the server failed to fulfill it due to an internal problem. There's nothing you can do on the client side to fix this; the server's owner needs to investigate.

  • 500 Internal Server Error: This is a generic server-side error. It's a catch-all for when something unexpected goes wrong on the server, like a bug in the code or a database connection failure. It essentially means "Oops, our server broke."

To help you remember these, here is a handy cheat sheet.

HTTP Status Codes Cheat Sheet
This cheat sheet provides a quick visual reference for the main HTTP status code families (2xx, 3xx, 4xx, 5xx) and explains the meaning of the most common codes within each category.

Seeing Status Codes in Action

Since you'll be using Postman for API testing, it's important to know where to look for these codes. When you send a request, the status code is one of the first pieces of information Postman shows you.

The following video demonstrates how you can see these status codes directly in Postman.

Common HTTP or REST request status codes

The video 'Common HTTP or REST request status codes' by qavbox includes practical demonstrations in Postman. This will help you see where these codes appear in a real tool.

Please watch these two short clips: A Successful Request (200 OK): Watch from 3:45 to 4:40. See how a successful GET request returns a 200 OK status. A Client Error (401 Unauthorized): Watch from 8:46 to 9:15. See what happens when an invalid authentication token is sent, resulting in a 401 Unauthorized error.

As you can see, the status code is displayed prominently in the response section of Postman, giving you immediate feedback on what happened with your API call.


Conclusion

You've now learned how to interpret the server's side of the conversation. By understanding HTTP status codes, you can quickly diagnose whether a problem lies with your request (a 4xx error) or with the server itself (a 5xx error), making you a much more effective developer.

Key Takeaways:

  • HTTP status codes are three-digit codes that the server sends back to tell the client the outcome of a request.
  • 2xx codes (e.g., 200 OK, 201 Created) mean the request was successful.
  • 4xx codes (e.g., 400 Bad Request, 401 Unauthorized, 404 Not Found) mean there was an error with the client's request.
  • 5xx codes (e.g., 500 Internal Server Error) mean the server failed to process a valid request.
  • Checking the status code is the first step in debugging any API interaction.

You now understand the client's request (URL, method) and the server's response (status code). But there's still one more piece of the puzzle. Both requests and responses carry extra information called headers.

In our next lesson, we'll explore HTTP headers and see how they are used to pass important metadata, like the format of the data being sent and information about authentication.