200 OK: An HTTP Status Code Indicating a Successful Request

スポンサーリンク
スポンサーリンク

About 200 OK

Overview of 200 OK

Request SuccessfulHTTP Status Code

200 OK

Overview The 200 OK status code indicates that the client’s request has been successfully processed and the server has returned a response to signify this success. It is used in a wide range of scenarios, such as retrieving resources with GET requests or confirming successful processing of POST requests.

Meaning The client’s request was successfully processed, and the server returned the requested resource or information.

When is 200 OK Returned?

  • When a GET request is successfully processed and the requested resource is returned
  • When a POST request is successful and the server returns the result
  • When an API request succeeds, and the expected data is included in the response

Examples of 200 OK

Successful GET Request

GET /index.html HTTP/1.1  
Host: example.com  

Response example:

HTTP/1.1 200 OK  
Content-Type: text/html; charset=UTF-8  

<html>
  <head><title>Example</title></head>
  <body><p>Hello, world!</p></body>
</html>

Explanation: This occurs when a client makes a GET request for a specific resource (e.g., index.html), and the server successfully processes the request and returns the resource content.

Successful API Request

GET /api/user/123 HTTP/1.1  
Host: example.com  

Response example:

HTTP/1.1 200 OK  
Content-Type: application/json  

{ 
  "id": 123, 
  "name": "John Doe", 
  "email": "john.doe@example.com" 
}

Explanation: This occurs when a client sends a request to an API endpoint, and the server correctly processes the request and returns data in JSON format.

Points to Note

Considerations when using the 200 OK status code:

  • Return meaningful responses
    Although 200 OK indicates a successful request, the response content must be meaningful to avoid confusing the client.
  • Clarify resource availability
    Only return 200 OK when the resource is successfully processed. If the processing is incomplete, use an appropriate error code.

Comparison with Related HTTP Status Codes

Here is an explanation of status codes related to 200 OK:

  • 201 Created: Used when a request succeeds, and a new resource is created.
  • 204 No Content: Used when a request succeeds, but the response body is empty.

Understanding these differences helps in appropriately using the 200 status code.