💡 If you like this website, please share it with your friends and network! 🚀
Back to All Questions
Question 13 of 100
Basic API Testing
Beginner

Q13: What is the Difference Between 2xx, 3xx, 4xx, and 5xx Status Codes?

🗂️Core Concept

What is the Difference Between 2xx, 3xx, 4xx, and 5xx Status Codes?

Key Takeaways & Architecture Summary

  • 2xx (Success): The request was successfully received, understood, and accepted.
  • 3xx (Redirection): Additional client actions are required to complete the request.
  • 4xx (Client Error): The request contains bad syntax or cannot be fulfilled due to client mistake.
  • 5xx (Server Error): The server failed to fulfill an otherwise valid client request.

Direct Answer Summary

The primary difference is the source and nature of the response. 2xx codes indicate successful execution. 3xx codes represent redirects where the client must perform extra hops. 4xx codes indicate that the client made an error (e.g., bad payload, missing auth). 5xx codes show that the server crashed or encountered a runtime exception while processing a structurally valid request.

⚠️ Senior Engineering Warning (Red Flag)

Avoid blaming the server for 4xx errors. If your automated tests assert a 4xx code, it usually means your test script is passing bad inputs, expired tokens, or hitting the wrong endpoint.

💡 STAR Architectural Explanation & Pro Tip

In microservices, mapping status codes accurately prevents debugging loops. A 5xx error propagates alerts to site reliability engineers, while a 4xx error is handled silently on the client.

RestAssuredTest.java
Rest-Assured + Java
// Rest-Assured status code range assertions
RestAssured.get("/api/v1/users")
    .then()
        .statusCode(Matchers.both(Matchers.greaterThanOrEqualTo(200))
        .and(Matchers.lessThan(300))); // Verify any success code