200 OK
Description
The 200 OK
status code indicates that the request has succeeded. The meaning of success depends on the HTTP method used:
- GET: The resource has been fetched and transmitted in the message body.
- HEAD: The representation headers are included in the response without any message body.
- PUT or POST: The resource describing the result of the action is transmitted in the message body.
- TRACE: The message body contains the request message as received by the server.
This is the standard response for successful HTTP requests and is the most common status code for a successful web request.
Syntax
The server responds with a 200 OK
status and includes the requested content:
HTTP/1.1 200 OK
Content-Type: [appropriate media type]
Content-Length: [length in bytes]
[Response body containing the requested resource or operation result]
Examples
GET Request Example
A client requests a web page:
Client Request:
Server Response:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
<!DOCTYPE html>
<html>
<head>
<title>Example Website</title>
</head>
<body>
<h1>Welcome to Example.com</h1>
<p>This is a sample page.</p>
</body>
</html>
API Request Example
A client requests data from an API:
Client Request:
GET /api/users/123 HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Server Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 237
{
"id": 123,
"name": "Jane Smith",
"email": "[email protected]",
"role": "administrator",
"created_at": "2023-05-15T14:30:00Z",
"last_login": "2023-06-10T09:15:22Z"
}
POST Request Example
A client submits form data:
Client Request:
POST /submit-form HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
name=John+Doe&email=john.doe%40example.com
Server Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 82
{
"status": "success",
"message": "Form submitted successfully",
"id": "12345"
}
Summary
The 200 OK
status code is the standard response for successful HTTP requests. It indicates that the server successfully processed the request, understood it, and provided an appropriate response. The exact meaning of "success" depends on the HTTP method used, but in all cases, it signifies that the client's request was handled without errors. The response body typically contains the requested resource or information about the result of the operation.