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

In our previous lesson, we examined the client's side of an HTTP conversation, focusing on the methods like GET, POST, and PUT that declare the client's intent. Now, we turn our attention to the server's reply. Once a server processes a request, it sends back a response, and a critical part of that response is the HTTP status code.

As a QA professional, you've certainly encountered codes like 200 OK, 404 Not Found, and 500 Internal Server Error daily in tools like Postman. This lesson aims to deepen that practical familiarity into a structured architectural understanding. We will explore the purpose and structure of the five classes of HTTP status codes (1xx–5xx). Understanding this standardized language is fundamental to diagnosing issues, building reliable client applications, and, crucially for your goal, evaluating the robustness and clarity of a system's API design.

The Server's Vocabulary: What are HTTP Status Codes?

An HTTP status code is a three-digit number included in the server's response that communicates the result of the client's request. Think of it as a universal, standardized language that prevents ambiguity. Instead of a client having to guess the outcome by inspecting the response body, the status code provides a clear, immediate signal.

This standardization is a cornerstone of the web, allowing different clients (browsers, mobile apps, test scripts) to interact consistently with any server, regardless of the server's underlying technology.

The video below offers an excellent introduction to where status codes fit within an HTTP response and why they are so important for standardizing communication.

5. Understanding HTTP for backend engineers, where it all starts

The video "Understanding HTTP for backend engineers" by Sriniously clearly explains the structure of HTTP messages.

Watch the segments that introduce HTTP messages, showing where the status code appears in a response, and then watch the explanation on what response codes are and why they are needed.


The Five Classes of Status Codes

Status codes are organized into five classes, determined by their first digit. Each class represents a different category of response.

This infographic provides a visual overview of the five classes of HTTP status codes and lists some of the most common codes within each category.

Let's explore each class in detail. For a comprehensive reference, the Postman team has an excellent guide that we will use throughout this section.

What Are HTTP Status Codes? Complete Guide

This guide from the Postman blog provides a thorough breakdown of the status code classes and the most important codes within them.

Please read the section titled The five classes. As you read about each class, pay close attention to the specific scenarios where each code is used.

Let's consolidate and highlight the most architecturally significant codes from each class.

1xx: Informational

These are the least common codes you'll see in day-to-day API testing. They indicate that the server has received the request and is continuing the process.

  • 100 Continue: The server has received the request headers and the client should proceed to send the request body. This is a performance optimization, allowing a server to reject a request early (e.g., due to bad headers) before the client wastes bandwidth sending a large body.

2xx: Success

This class indicates that the client's request was successfully received, understood, and accepted. These are the codes you hope to see.

  • 200 OK: The standard response for a successful request. The payload will vary based on the request method (e.g., the requested data for a GET, a confirmation message for a PUT).
  • 201 Created: The request was successful, and a new resource was created as a result. This is the ideal response to a POST request that creates a new entity. A well-designed API will also include a Location header in the response, with a URL pointing to the newly created resource.
  • 204 No Content: The server successfully processed the request but has no content to send back in the response body. This is often used for DELETE requests, where the action is successful, and the response simply needs to confirm that deletion.

3xx: Redirection

This class indicates that the client must take additional action to complete the request, typically by navigating to a new URL.

  • 301 Moved Permanently: The requested resource has been permanently moved to a new URL. Clients and search engines should update their links to the new URL provided in the Location header.
  • 302 Found: The resource is temporarily at a different URL. Clients should continue to use the original URL for future requests.
  • 304 Not Modified: This is a response to a conditional GET request. It tells the client that the resource has not changed since the last request, so the client can safely use its cached version, saving bandwidth and improving performance.

4xx: Client Error

This class is for situations where the request appears to be invalid or cannot be fulfilled due to an error on the client's side. As a QA engineer, you spend a lot of time validating that an API correctly returns these codes for invalid inputs.

  • 400 Bad Request: A generic error indicating the server could not understand the request due to malformed syntax (e.g., invalid JSON) or missing parameters.
  • 401 Unauthorized: Authentication is required, but the client either didn't provide credentials or the credentials were invalid (e.g., a missing or expired API key/token). Note: Despite the name, this is about authentication (who are you?), not authorization.
  • 403 Forbidden: The client is authenticated, but does not have the necessary permissions to access the resource. This is the correct code for authorization failures (what are you allowed to do?).
  • 404 Not Found: The server cannot find the requested resource. The URL is valid, but the specific resource doesn't exist.
  • 429 Too Many Requests: The client has sent too many requests in a given amount of time ("rate limiting"). Well-designed APIs often include a Retry-After header indicating how long the client should wait before trying again.

5xx: Server Error

This class indicates that the server failed to fulfill a valid request due to an error on its side. These errors point to problems with the backend code or infrastructure.

  • 500 Internal Server Error: A generic, catch-all error indicating that something unexpected went wrong on the server. It means the server doesn't have a more specific 5xx code to use.
  • 502 Bad Gateway: This typically occurs in distributed systems (like microservice architectures). It means a server acting as a gateway or proxy received an invalid response from an upstream server it was communicating with.
  • 503 Service Unavailable: The server is temporarily unable to handle the request, perhaps due to being overloaded or down for maintenance.
  • 504 Gateway Timeout: Similar to 502, this occurs when a gateway or proxy server did not receive a timely response from an upstream server. This points to a dependency service being slow or unresponsive.

To hear these explanations reinforced with different examples, the following video provides another clear walkthrough.

HTTP Status Code Explained | 11 Popular HTTP Status Codes with explanation | Bad Gateway 502 - Demo

In "HTTP Status Code Explained," Abhishek Veeramalla provides a practical overview from a DevOps/SRE perspective.

Watch the sections that cover the families of codes, the 2xx codes, the 3xx codes, the 4xx codes, and the 5xx codes. Pay special attention to his distinction between 401 and 403.


From Observation to Critique: Anti-Patterns in Practice

Your experience in QA means you're an expert at finding bugs. A common source of bugs and brittle system design is the improper use of status codes. Moving from a QA role towards architecture means not just identifying that the system returned the "wrong" code, but understanding why it's wrong and the negative consequences of that choice.

What Are HTTP Status Codes? Complete Guide

Let's revisit the Postman guide to look at common mistakes and real-world application.

First, read the section on common mistakes. This will formalize many of the issues you've likely encountered during testing. Then, review the examples in different scenarios to see how these codes map to real business logic in e-commerce, authentication, and microservices.

The most significant anti-pattern is returning a 200 OK status for an operation that failed, with the error details hidden in the response body. This breaks the fundamental contract of HTTP, forcing every client to parse the body to determine the true outcome of the request. A robust system uses the status code correctly to signal the outcome, and reserves the body for providing additional context.


Conclusion

In this lesson, we demystified the language of server responses by exploring the five classes of HTTP status codes. We moved beyond a simple list of definitions to understand their architectural significance in creating clear, predictable, and reliable systems.

Key takeaways include:

  • HTTP status codes are a standardized three-digit language for a server to communicate the outcome of a request.
  • The codes are grouped into five classes: 1xx (Informational), 2xx (Success), 3xx (Redirection), 4xx (Client Error), and 5xx (Server Error).
  • Using specific codes like 201 Created or 204 No Content is superior to a generic 200 OK as it provides more semantic meaning.
  • The distinction between 401 Unauthorized (authentication failure) and 403 Forbidden (authorization failure) is a critical concept in system security.
  • Server errors like 502 Bad Gateway and 504 Gateway Timeout are essential for diagnosing problems in modern, distributed architectures.

So far, we have covered the full lifecycle of an HTTP request: the client sends a request with a method, and the server replies with a response containing a status code. However, all of this communication has been happening in the clear. In our next and final lesson of this module, we will examine TLS/SSL, the cryptographic protocol that wraps HTTP to create HTTPS, ensuring our data is secure as it travels across the network.