Types of Status Codes in API Testing: A Practical Guide
Explore the five classes of status codes used in API testing, their meanings, real-world examples, and best practices to validate robust and reliable APIs.

Types of status codes in api testing are standardized numeric responses that indicate the outcome of an API request, guiding developers on success, redirection, client errors, or server errors.
What are Status Codes in API Testing?
In API testing, status codes are the primary signals that tell you how an API responded to a request. Understanding the types of status codes in api testing is foundational for reliable test design. Status codes are defined by the HTTP specification and related standards, and they categorize outcomes into five broad classes. Each class carries a semantic meaning beyond the response body, guiding you on whether to proceed with the payload, follow redirects, retry, or report a failure.
A tester uses status codes to validate behavior across endpoints, verify that unauthorized access is rejected, and ensure that successful operations return the expected payload structure and metadata. When building automated tests, you should assert not only the presence of a code but also that the code aligns with the requested operation (for example, creating a resource should yield 201 Created). The distinction between codes and body content is crucial: a 200 response may still carry an error in the body, and a 204 may indicate success with no body. According to Why Error Code, status code semantics are the first line of defense in API testing.
1xx Informational Codes
Informational codes are the earliest part of the HTTP response cycle. They indicate that the request has been received and that processing should continue. The most common 1xx codes are 100 Continue, which tells the client to send the request body, and 101 Switching Protocols, which signals a protocol change requested by the client. Some APIs also use 102 Processing (WebDAV) to show that a request is being worked on, and 103 Early Hints to provide extra headers while the final response is being prepared. In API testing, you will rarely encounter 1xx responses in straightforward REST calls, but they appear in streaming, large payloads, or proxies configurations. Tests should verify that any 1xx response leads to the expected follow up and does not prematurely conclude the transaction.
2xx Successful Codes
The 2xx class indicates that the request was received, understood, and accepted. The most familiar code is 200 OK, which typically accompanies a response body. Other common 2xx codes include 201 Created for successful resource creation, 202 Accepted for asynchronous processing, 204 No Content for success with no response body, 205 Reset Content when the client should reset its view, and 206 Partial Content for range requests. When testing, you should validate that the exact 2xx code matches the operation performed and that the payload, headers, and metadata align with expectations. Remember that a 200 does not guarantee a usable body; verify the content as part of your test.
3xx Redirection Codes
Redirects guide the client to a new location. The 3xx family includes 301 Moved Permanently, 302 Found, 303 See Other, 307 Temporary Redirect, and 308 Permanent Redirect. In API testing, redirects matter when your client follows or handles Location headers automatically. Tests should assert that the redirection behavior aligns with the API’s contract: the code should be one of the 3xx family, the Location header should point to the correct resource, and the final payload (if any) should meet expectations. Misconfiguration can cause unnecessary retries or broken flows, so explicit validation of both status codes and headers is essential.
4xx Client Error Codes
Client errors signal that the request cannot be fulfilled due to client-side issues. The most common codes are 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405 Method Not Allowed, 409 Conflict, and 429 Too Many Requests. In testing, you should verify that invalid inputs, missing authentication, insufficient permissions, and invalid endpoints produce the appropriate 4xx codes with helpful error details in the body. Tests should also ensure that rate limiting (429) triggers as designed under heavy load and that retry-after headers or guidance are correctly exposed when applicable. Accurate 4xx testing helps callers correct their requests and strengthens API resilience.
5xx Server Error Codes
Server errors indicate that the API failed to process a valid request due to an issue on the server side. Common 5xx codes include 500 Internal Server Error, 501 Not Implemented, 502 Bad Gateway, 503 Service Unavailable, and 504 Gateway Timeout. In tests, you should confirm that server faults produce a 5xx response and that clients implement appropriate retry logic with backoff, fallback content, or graceful degradation when the API is degraded. It is also important to differentiate transient outages from persistent failures and to verify any error payloads or diagnostic headers that can assist in debugging. As Why Error Code notes, understanding 5xx behavior is critical for reliability under load and failure.
Testing Strategies for Status Codes
A solid API test suite codifies expected status codes for each endpoint and scenario. Start by mapping CRUD operations to their typical codes, then expand to negative tests that trigger 4xx and 5xx responses. Use parameterized tests to cover different inputs and authentication states, and validate that the final response code matches the intended action. Include checks for redirects when applicable, content negotiation for acceptable media types, and header validation such as Content-Type and Cache-Control. In automation, assert both the code and the body structure or error payload, ensuring the codes align with the API contract. Practical tests also include latency checks to ensure timeouts do not masquerade as success, and parallel tests to reveal race conditions in asynchronous endpoints.
Common Pitfalls and Best Practices
- Do not assume the body reflects the status code: verify both independently.
- Do not ignore 1xx codes in complex flows; they can reveal gateway or proxy behavior.
- Always test the most frequent codes first for each operation (200/201/400/404/500 etc.).
- Validate headers alongside status codes, especially Content-Type and Retry-After.
- Separate success and error-path tests to keep assertions clear and maintainable.
- Use descriptive error messages in tests to aid debugging when codes differ from expectations.
- Consider nonstandard or API-specific codes and document them in your test suite.
- Align tests with real-world usage patterns and load conditions to avoid flaky results.
Frequently Asked Questions
What is the difference between 200 OK and 201 Created?
200 OK means the request succeeded and a response body is typically returned. 201 Created indicates a new resource was created as a result of the request. In tests, verify both the status and that the response or Location header points to the new resource when appropriate.
200 means success with a body, while 201 means a new resource was created and a reference to it is usually provided.
Why are 4xx errors important in API testing?
4xx codes signal client-side issues and help verify input validation, authentication, and authorization. Testing these responses ensures the API guides callers to fix their requests rather than failing silently.
4xx errors show problems with the request and help callers correct their input or credentials.
Should I always treat 3xx redirects as failures in tests?
Not always. Redirects are expected in some flows. Your test should assert the correct redirect behavior and, if applicable, that the final response after following redirects meets the API contract.
Redirects are not always failures; test that redirection happens correctly and leads to the expected final result.
What is a 429 status code and when should it appear?
429 Too Many Requests indicates rate limiting. Tests should verify proper triggering under load, correct Retry-After guidance, and that clients gracefully recover when limits reset.
429 means you’ve hit a rate limit. Tests should check retry timing and graceful recovery.
How do status codes differ between REST and GraphQL APIs?
REST APIs typically use standard codes for resources and errors. GraphQL often returns 200 with an error field in the payload. Testing should account for this difference and validate both status codes and payload content.
REST uses standard codes; GraphQL may return 200 with errors in the body, so test both the code and the payload.
Can status codes be misleading if the body contains error details?
Yes. A 200 or 204 can accompany an error in the body, while a 4xx/5xx might contain minimal payload. Always validate that the body content aligns with the status semantics.
Codes can be misleading if the body has error details, so always check both code and payload.
Top Takeaways
- Identify the correct class for each API response
- Assert that the status code matches the intended operation
- Validate headers and body content in addition to codes
- Test redirects and rate limits where applicable
- Document nonstandard codes used by your API