2xx Success Codes
Introduction
The 2xx success status codes are the HTTP responses that tell a client the server successfully received, understood, and processed the request. In API testing, these codes are encountered more often than any other status-code group because they represent normal successful behavior: retrieving data, creating a resource, accepting work for background processing, updating information, deleting records, logging in, searching, downloading files, and completing many other operations.
At first glance, 2xx codes may look simple. Many beginners assume that any successful API response can return 200 OK and that the test is complete as long as the status code is in the success range. In real API design and testing, that is not enough. Different 2xx status codes communicate different kinds of success. A successful retrieval is different from a successful creation. A request accepted for later processing is different from a request already completed. A successful operation with no response body is different from a successful operation that returns data. Understanding these differences helps testers write stronger assertions and helps developers design APIs that communicate clearly.
The goal of this tutorial is to explain 2xx success codes from a practical API testing point of view. We will look at the most common codes, especially 200 OK, 201 Created, 202 Accepted, and 204 No Content. We will also discuss less common success codes, response-body expectations, headers, asynchronous workflows, common mistakes, and how to explain these concepts in interviews.
What Are 2xx Success Codes?
The 2xx range covers HTTP status codes from 200 to 299. These codes are final responses, unlike 1xx informational responses. When a client receives a 2xx response, the server is saying that the request reached the server, the request was understood, and the server handled it successfully according to the meaning of that specific code.
A simple definition is this: 2xx success codes indicate that the server successfully processed the client's request. The word "successfully" must be understood in context. For 200 OK, success usually means the requested result is available now. For 201 Created, success means a new resource was created. For 202 Accepted, success means the request was accepted but processing is still pending. For 204 No Content, success means the operation completed and there is intentionally no response body.
This is why API testers should not validate only that the status code starts with the digit 2. A broad assertion such as "status code should be less than 300" may be acceptable for some low-level availability checks, but it is weak for functional API testing. A functional test should usually validate the exact expected status code because the exact code expresses the API contract.
Range and Common 2xx Status Codes
The most frequently used 2xx status codes in REST API testing are 200 OK, 201 Created, 202 Accepted, and 204 No Content. These four cover the majority of successful API operations. A GET request that returns data usually returns 200 OK. A POST request that creates a new resource usually returns 201 Created. A long-running operation that is accepted for background processing often returns 202 Accepted. A DELETE request that succeeds without returning a body commonly returns 204 No Content.
Other 2xx codes exist, including 203 Non-Authoritative Information, 205 Reset Content, 206 Partial Content, 207 Multi-Status, 208 Already Reported, and 226 IM Used. These are valid HTTP codes, but they are less common in everyday REST API work. Some are tied to proxies, range requests, WebDAV, or specialized HTTP features. A tester should know they exist, but in most projects, the practical focus remains on 200, 201, 202, and 204.
Good API design uses the status code that best matches the operation. Good API testing verifies that match. When the response code, body, and headers tell a consistent story, client applications become easier to build, automate, debug, and maintain.
200 OK
200 OK is the most common HTTP success code. It means the request was successfully processed, and the response usually contains the requested representation or result. When a user fetches profile details, searches products, gets order history, submits login credentials, or updates a resource and receives the updated representation, 200 OK is commonly used.
For example, a client may send this request:
GET /users/101
The server may respond with:
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 101,
"name": "John"
}
In this case, the status code confirms that the request was successful, and the body returns the user data. For a GET request, a 200 OK response normally has a response body. The tester should validate not only the status code but also the body content, response headers, schema, business fields, data types, and any security-sensitive behavior such as whether private fields are exposed.
200 OK can also be used for successful PUT or PATCH operations when the server returns the updated resource. Some APIs use 200 OK for DELETE operations when they return a confirmation message or the deleted resource summary. This is not always wrong, but the behavior should be consistent and documented. If the API contract says DELETE returns no body, 204 No Content is usually more appropriate.
Testing 200 OK Responses
Testing 200 OK starts with checking that the correct operation has actually succeeded. A status code alone does not prove that the right data was returned. For a user-profile endpoint, verify the expected user ID, name, email, role, and visibility rules. For a product search endpoint, verify filters, sorting, pagination, total count, and result relevance. For a login endpoint, verify token presence, token format, user permissions, expiry fields, and secure headers where applicable.
Header validation is also important. A JSON API should usually return an appropriate Content-Type header such as application/json. Cache headers may matter for public read APIs. Security headers may matter for browser-facing APIs. Correlation IDs may matter for traceability. In professional API testing, success validation means checking the full response contract, not only the numeric status code.
Negative comparison is useful too. If a valid request returns 200 OK, then an invalid request should not also return 200 OK with an error message hidden in the body. A common poor design is returning 200 OK for failed operations and putting "success": false inside the response body. This forces every client to parse the body to detect failure and weakens HTTP semantics. A tester should flag this behavior when the API contract expects proper 4xx or 5xx responses.
201 Created
201 Created indicates that the request succeeded and a new resource was created on the server. It is commonly returned after a successful POST request. If a client creates a user, order, ticket, customer, address, project, or any other new entity, 201 Created is often the most meaningful success response.
A simple request may look like this:
POST /users
Content-Type: application/json
{
"name": "John"
}
The response may be:
HTTP/1.1 201 Created
Location: /users/101
Content-Type: application/json
{
"id": 101,
"name": "John"
}
The Location header is important because it points to the newly created resource. Not every API returns this header, but it is a strong and useful pattern. The response body may include the created resource, the generated ID, timestamps, default values, links, or other server-generated fields. A good test should verify that the resource was created correctly and that the response tells the client how to access it afterward.
201 Created should be used only when something new was actually created. If a POST request performs a search, validates credentials, or triggers an action without creating a resource, 200 OK, 202 Accepted, or another code may be more appropriate depending on the behavior.
Testing 201 Created Responses
Testing 201 Created requires more than checking the response code. The tester should verify that the resource exists after creation. This may be done by calling a GET endpoint for the newly created ID, checking the returned body, validating database state when database checks are allowed, or confirming the new record appears in an application workflow.
The generated identifier is a key validation point. If the API creates a user, order, or ticket, the response should include a usable ID or a location where the resource can be retrieved. The ID should not be null, empty, duplicated, or incorrectly formatted. If the system uses UUIDs, numeric IDs, slugs, or composite keys, the response should match the expected format.
The Location header should be tested when it is part of the API contract. Verify that the header is present, points to the correct resource path, and can be used to retrieve the created resource. If the response body and Location header disagree, the API becomes confusing. For example, if the body says the new user ID is 101 but the Location header points to /users/102, that is a serious contract defect.
Duplicate-creation behavior should also be tested. If the same creation request is sent twice, should the API create two records, return a conflict, or behave idempotently using an idempotency key? The answer depends on business rules. A payment API may require idempotency to avoid duplicate charges, while a comment API may allow multiple comments with the same text. The status code should reflect the expected behavior.
202 Accepted
202 Accepted means the server accepted the request, but processing has not completed yet. This code is commonly used for asynchronous operations, background jobs, queued tasks, and workflows that take longer than a normal request-response cycle. Report generation, video processing, image conversion, bulk import, email sending, payment settlement, and large file processing are common examples.
A request may look like this:
POST /reports
Content-Type: application/json
{
"type": "yearly-financial-summary"
}
The server may immediately respond:
HTTP/1.1 202 Accepted
Content-Type: application/json
{
"jobId": "ABC123",
"status": "Processing"
}
This response does not mean the report is ready. It means the request was valid enough to be accepted and the server will process it later. The client usually needs a way to check progress, such as GET /reports/ABC123, a job-status endpoint, webhook notification, polling mechanism, or callback.
202 Accepted is different from 201 Created. A 201 response says the new resource exists now. A 202 response says the work has been accepted, but the final result may not exist yet. It is also different from 1xx informational responses. A 202 response is final for the initial request even though the business process continues asynchronously.
Testing 202 Accepted Responses
Testing 202 Accepted requires validating both immediate acceptance and eventual outcome. The immediate response should include enough information for the client to track the background work. A job ID, status URL, request ID, estimated state, or callback reference may be required. If the API returns 202 but gives no way to check the result, clients are left guessing.
The next step is to test the follow-up flow. After receiving the job ID, the test can poll a status endpoint until the job reaches a terminal state such as Completed, Failed, Cancelled, or Expired. Tests should use controlled waits and timeouts rather than fixed long sleeps. The final result should be validated once processing completes. For a report job, verify that the report exists, has the expected format, contains correct data, and is accessible only to authorized users.
Failure paths are important. A request can be accepted and later fail during processing. The API should expose that failure clearly. The status endpoint should not remain in "Processing" forever. It should provide meaningful states, error messages, or error codes. For automation, this means tests should cover not only the happy path but also validation of expired jobs, failed jobs, unauthorized status checks, and invalid job IDs.
Do not use 202 Accepted for operations that complete immediately unless there is a clear architectural reason. If a user update is completed before the response is returned, 200 OK or 204 No Content is usually better. Overusing 202 makes clients unnecessarily complex because they must implement polling or tracking even when no background processing is needed.
204 No Content
204 No Content indicates that the request succeeded, but the server has no response body to return. This status code is commonly used for DELETE requests, logout operations, and update operations where the client does not need a response body after success.
A typical DELETE request may look like this:
DELETE /users/101
The response may be:
HTTP/1.1 204 No Content
There is no JSON body, no confirmation object, and no message string. The absence of a body is part of the meaning. Response headers may still be present, but the body should be empty. This is where many APIs make mistakes. Returning 204 No Content with a response body contradicts the meaning of the code and can confuse clients.
204 No Content is useful when the client already has enough context. If a user clicks delete on a saved address, the client knows which address was deleted. It may not need the server to return the deleted address again. If a client sends a PUT request to update preferences and no updated representation is required, a 204 response can keep the interaction lightweight.
Testing 204 No Content Responses
Testing 204 No Content has one special requirement: verify that the response body is actually empty. Some APIs return a body such as {"message":"deleted"} with status 204. That should be corrected either by changing the status to 200 OK with a body or by removing the body and keeping 204 No Content.
The tester should also verify the real business outcome. For a DELETE request, call the resource afterward and confirm it is unavailable, removed, soft-deleted, or hidden according to business rules. The follow-up response might be 404 Not Found, 410 Gone, or a record with a deleted flag, depending on the API design. The important point is that the operation actually happened.
For update operations that return 204, verify the state through a subsequent GET call. If a user preference update returns 204 No Content, the test should retrieve the preferences and confirm the value changed. Without this second check, the test only proves that the server claimed success, not that the data was updated correctly.
Headers should also be reviewed. Since there is no body, headers may carry useful information such as cache directives or correlation IDs. However, do not expect Content-Type: application/json to be meaningful when no JSON body exists. A strict API contract should define which headers are expected for 204 responses.
Other 2xx Status Codes
Although most API testers mainly use 200, 201, 202, and 204, the rest of the 2xx family is worth understanding. 203 Non-Authoritative Information means the returned metadata is not exactly from the origin server but has been modified by a transforming proxy or intermediary. This is uncommon in typical application APIs but may appear in systems with caching or transformation layers.
205 Reset Content tells the client that the request succeeded and the client should reset the document view or input form. This code is rare in modern REST APIs, but the idea is that the server acknowledges success and instructs the client to clear the current input context.
206 Partial Content is used when the server returns only part of a resource, usually because the client requested a byte range. This is common for media streaming, resumable downloads, file preview, and large content delivery. A tester working with downloads, videos, or large files should understand 206 Partial Content because it validates range-request behavior rather than ordinary full-resource retrieval.
207 Multi-Status and 208 Already Reported are associated with WebDAV and multi-resource operations. They are not common in normal JSON REST APIs, but they can appear in document-management or file-management systems. 226 IM Used relates to delta encoding and is rarely seen in standard API projects.
Comparison of Common 2xx Codes
The easiest way to remember common 2xx codes is to connect each one with a business meaning. 200 OK means the request succeeded and a useful response is usually returned. 201 Created means a new resource now exists. 202 Accepted means the request is accepted for processing that will complete later. 204 No Content means the request succeeded and there is intentionally no response body.
For response bodies, 200 OK usually includes a body, 201 Created often includes the created resource, 202 Accepted may include a job ID or tracking information, and 204 No Content must not include a body. This body expectation is one of the most practical testing differences among these codes.
The operation also matters. Retrieve user details: usually 200 OK. Search products: usually 200 OK. Create a new user: usually 201 Created. Upload a report request that starts background processing: usually 202 Accepted. Delete a resource with no response body: usually 204 No Content. Update a resource: 200 OK if returning the updated representation, or 204 No Content if no body is returned.
Choosing the Right 2xx Code
Choosing the right 2xx code is part of API contract design. The status code should tell the client what happened without requiring unnecessary interpretation. If a POST request creates a resource, returning 201 Created is clearer than returning 200 OK. If processing continues in the background, returning 202 Accepted is clearer than pretending the final result is already complete. If there is no response body, returning 204 No Content is clearer than returning an empty JSON object with 200 OK.
Consistency is just as important as correctness. If one create endpoint returns 201 and another similar create endpoint returns 200 without explanation, client developers and testers must handle unnecessary variation. A consistent API is easier to automate and easier to document. Standards should be agreed at API design time, not discovered through inconsistent implementation.
There are cases where more than one code can be reasonable. A DELETE operation may return 200 OK with a body or 204 No Content without a body. A PUT update may return 200 OK with the updated resource or 204 No Content if nothing is returned. The important requirement is that the API contract clearly defines the behavior and the implementation follows it consistently.
API Testing Considerations
When validating 2xx responses, testers should combine status-code checks with body validation, header validation, schema validation, database or state validation when appropriate, and follow-up API calls. A success code is only one part of the response contract. A 200 OK response with missing fields, wrong data, incorrect pagination, or private information leakage is still defective.
For 200 OK, verify that the expected data is returned, the response schema is correct, the content type is correct, filters and sorting work, and authorization rules are respected. For 201 Created, verify creation, generated IDs, default values, Location header, and retrievability. For 202 Accepted, verify job tracking, background processing, terminal status, and final result. For 204 No Content, verify the absence of body and the actual state change.
Testers should also check performance and reliability expectations. A success response that takes too long may still hurt the user experience. A 202 Accepted response that accepts work but never completes is not practically successful. A 201 Created response that creates duplicate records during retries may cause business risk. Success testing should include the behavior around the status code, not just the code itself.
Security is also relevant. A successful response should not expose data the user is not allowed to see. If an unauthorized user gets 200 OK for another user's private order details, the status code is successful from a transport point of view but wrong from a security point of view. Always connect success-code validation to business authorization rules.
Real-World Examples
Imagine an e-commerce application where a customer searches for laptops. The client sends GET /products?category=laptops, and the server returns 200 OK with a list of products. A good test verifies that the result contains laptops, the response follows the expected schema, pagination works, prices are visible in the correct currency, and unavailable products are handled according to rules.
Now consider user registration. The client sends POST /users with valid registration details. The server creates a new account and returns 201 Created. A good test verifies that the response contains the new user ID, the Location header points to that user, the account can be retrieved, default profile fields are set correctly, and duplicate email registration is rejected properly.
For an asynchronous example, a user requests a yearly financial report. The report takes several minutes to generate, so the server returns 202 Accepted with a job ID. The client checks the report status later. A proper test validates the initial 202 response, polls the status endpoint with a controlled timeout, verifies the completed report, and checks that unauthorized users cannot access someone else's report.
For 204 No Content, think about deleting a saved address. The client sends DELETE /addresses/25, and the server returns 204 with no body. The test should confirm that the body is empty and then verify that the address no longer appears in the user's saved-address list.
Common Mistakes with 2xx Codes
One common mistake is returning 200 OK for every successful operation. While it may work technically, it reduces meaning. A creation response should usually be 201 Created. A background-processing response should usually be 202 Accepted. A successful no-body response should usually be 204 No Content. Using only 200 makes the API less expressive.
Another mistake is returning 200 OK for errors. Some APIs return HTTP 200 with a body such as {"error":"Invalid password"}. This forces clients to inspect the body to detect failure and breaks common monitoring, logging, retry, and alerting expectations. Invalid client input should generally return a 4xx status code, not a 2xx success code.
A third mistake is returning 204 No Content with a body. If the API wants to return a confirmation message, it should usually use 200 OK. If it uses 204 No Content, the body should be empty. This is easy to miss if tests only check status codes and never check response bodies.
Another mistake is using 202 Accepted when processing is already complete. This makes clients implement status tracking unnecessarily. Use 202 when asynchronous processing is real and when the API provides a way to track the final result.
Debugging Success Responses
When a success response behaves incorrectly, start by separating transport success from business success. A 200 OK response means the server successfully returned a response, but it does not automatically mean the business rule is correct. The wrong user data, missing records, duplicate creation, incorrect totals, or unauthorized access can all occur with a 2xx status code.
Next, check whether the status code matches the endpoint contract. If the API documentation says a successful POST returns 201 but the implementation returns 200, the defect may be contract inconsistency rather than functional failure. If the contract itself is unclear, the team should clarify it and update tests accordingly.
Then inspect the response body and headers. For 201, review generated IDs and Location. For 202, review job tracking information. For 204, confirm the body is empty. Use server logs, database checks, event logs, or follow-up GET calls when needed. A complete debugging process traces the request from client input to server processing to response output and persisted state.
In CI/CD pipelines, success-code defects can be difficult to spot if tests are too broad. An assertion like "status code is between 200 and 299" may allow a 200 response where 201 was expected. Exact assertions improve feedback. When tests fail, the failure message should say what was expected and why, such as "Expected 201 Created because a new user should be created, but received 200 OK."
Best Practices
Use 200 OK for successful retrieval and for operations where the response body contains the result or updated representation. Use 201 Created when a new resource is successfully created. Use 202 Accepted when the server accepts work that will complete asynchronously. Use 204 No Content when the request succeeds and no response body is needed.
Document the expected status code for each endpoint and each major scenario. The same endpoint may return different success codes depending on behavior, but those differences should be clear. For example, a create endpoint may return 201 for creation and 202 for queued creation if processing is asynchronous. A well-written API specification avoids guesswork.
In automation, assert the exact expected success code unless the test is intentionally broad. Validate response body rules, headers, schema, and resulting state. For 202 flows, automate eventual-result validation carefully with polling and timeouts. For 204 flows, explicitly verify that the response body is empty.
Finally, treat status codes as part of communication quality. APIs are contracts between systems. A precise success code helps client developers, QA engineers, automation frameworks, monitoring systems, and production support teams understand what happened quickly.
Interview-Ready Explanation
2xx success HTTP status codes indicate that the server successfully received, understood, and processed the client's request. The most common success codes in REST APIs are 200 OK, 201 Created, 202 Accepted, and 204 No Content.
200 OK means the request succeeded and usually returns a response body. 201 Created means a new resource was created, often with a Location header pointing to that resource. 202 Accepted means the request was accepted but processing will finish later, so it is used for asynchronous jobs. 204 No Content means the operation succeeded but there is no response body.
In API testing, we should validate the exact expected status code, response body, headers, schema, and final business outcome. We should not use 200 for every success scenario because each 2xx code has a specific meaning. Correct use of 2xx codes makes APIs easier to understand, automate, debug, and maintain.
Key Takeaway
2xx success codes are not just positive numbers returned by an API. They are meaningful communication signals. 200 OK tells the client that the result is available. 201 Created tells the client that something new now exists. 202 Accepted tells the client that work has been accepted for later completion. 204 No Content tells the client that the operation succeeded and no body is returned.
For API testers, the practical rule is simple: validate the exact success code that matches the business operation, then verify the body, headers, and resulting state. A successful API test should prove not only that the server returned a 2xx status code, but that the API did the correct thing in the correct way.