< HTTP/1.1 200 OKHTTP 200 OK: What It Means and When to Use It
200 OK means the request succeeded and the response carries the result. What a 200 should contain, and when 201, 204 or 206 is the better answer for your API.
- Cacheable
- Yes, by default
- Client action
- Use the response body
- Usually sent by
- Origin app
- Spec
- RFC 9110 §15.3.1
On this page
- What is 200 OK?
- When Servers Return 200
- GET Request - Resource Retrieved
- POST Request - Action Completed
- PUT Request - Resource Updated
- DELETE Request - Resource Removed
- Response Body Content
- HTML Page
- JSON Data
- Image File
- Empty Array (Valid 200)
- Common Response Headers
- 200 OK vs Other Success Codes
- Choosing the Right Code
- Getting 200 OK right
- Do Return Useful Data
- Don’t Return 200 for Errors
- Include Appropriate Headers
- JavaScript Handling
- Fetch API
- Checking Specifically for 200
- With Error Handling
- API Response Patterns
- Standard Success Response
- Paginated Response
- Response with Metadata
- Try It Yourself
- Try it with curl
- Related Status Codes
- Related Concepts
TL;DR: 200 OK means your request succeeded. The server processed it and is returning the requested data.
200 OK is the most common HTTP status code. It means everything worked—the server received your request, understood it, processed it successfully, and is sending back the result.
What is 200 OK?
When a server returns 200 OK, it’s saying “your request succeeded, here’s what you asked for”:
GET /api/users/123 HTTP/1.1
Host: api.example.com
Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 89
{
"id": 123,
"name": "Alice Johnson",
"email": "alice@example.com"
}
When Servers Return 200
GET Request - Resource Retrieved
GET /products/456 HTTP/1.1
Host: shop.example.com
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 456,
"name": "Wireless Headphones",
"price": 79.99
}
POST Request - Action Completed
POST /api/login HTTP/1.1
Content-Type: application/json
{"email": "user@example.com", "password": "..."}
HTTP/1.1 200 OK
Content-Type: application/json
{
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": {"id": 123, "name": "User"}
}
PUT Request - Resource Updated
PUT /api/users/123 HTTP/1.1
Content-Type: application/json
{"name": "Alice Smith"}
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 123,
"name": "Alice Smith",
"updatedAt": "2026-01-19T10:30:00Z"
}
DELETE Request - Resource Removed
DELETE /api/posts/789 HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
{
"message": "Post deleted successfully",
"deletedId": 789
}
Response Body Content
The response body varies by request type:
HTML Page
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<body><h1>Hello, World!</h1></body>
</html>
JSON Data
HTTP/1.1 200 OK
Content-Type: application/json
{
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
],
"total": 2
}
Image File
HTTP/1.1 200 OK
Content-Type: image/png
Content-Length: 12345
[binary PNG data]
Empty Array (Valid 200)
HTTP/1.1 200 OK
Content-Type: application/json
{
"results": [],
"total": 0
}
Common Response Headers
| Header | Purpose | Example |
|---|---|---|
Content-Type | Body format | application/json |
Content-Length | Body size | 1234 |
Cache-Control | Caching rules | max-age=3600 |
ETag | Resource version | "abc123" |
Last-Modified | Last change | Sat, 18 Jan 2026 10:00:00 GMT |
Set-Cookie | Set cookies | session=xyz; HttpOnly |
200 OK vs Other Success Codes
| Code | Name | When to Use |
|---|---|---|
| 200 | OK | General success with response body |
| 201 | Created | New resource created (POST) |
| 202 | Accepted | Request queued for processing |
| 204 | No Content | Success but no body to return |
Choosing the Right Code
# GET request - use 200
GET /users/123 → 200 OK with user data
# POST creating resource - use 201
POST /users → 201 Created with new user + Location header
# DELETE with no response body - use 204
DELETE /users/123 → 204 No Content
# POST triggering async job - use 202
POST /reports/generate → 202 Accepted
Getting 200 OK right
Do Return Useful Data
HTTP/1.1 200 OK
Content-Type: application/json
{
"success": true,
"data": {
"id": 123,
"name": "Alice"
},
"meta": {
"requestId": "req-abc-123",
"timestamp": "2026-01-19T10:30:00Z"
}
}
Don’t Return 200 for Errors
# ❌ Bad: 200 with error in body
HTTP/1.1 200 OK
{"error": "User not found"}
# ✅ Good: Proper error status
HTTP/1.1 404 Not Found
{"error": "User not found"}
Include Appropriate Headers
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=300
ETag: "v1-abc123"
X-Request-ID: req-xyz-789
{"data": "..."}
JavaScript Handling
Fetch API
const response = await fetch('/api/users/123')
if (response.ok) {
// true for 200-299
const user = await response.json()
console.log('User:', user)
} else {
console.error('Request failed:', response.status)
}
Checking Specifically for 200
const response = await fetch('/api/data')
if (response.status === 200) {
const data = await response.json()
// Process successful response
}
With Error Handling
async function fetchUser(id) {
const response = await fetch(`/api/users/${id}`)
if (!response.ok) {
throw new Error(`HTTP ${response.status}`)
}
return response.json()
}
try {
const user = await fetchUser(123)
displayUser(user)
} catch (error) {
showError(error.message)
}
API Response Patterns
Standard Success Response
{
"status": "success",
"data": {
"id": 123,
"name": "Alice"
}
}
Paginated Response
{
"data": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
],
"pagination": {
"page": 1,
"perPage": 20,
"total": 150,
"totalPages": 8
}
}
Response with Metadata
{
"data": { "id": 123 },
"meta": {
"requestId": "req-abc",
"processingTime": "45ms",
"apiVersion": "v1"
}
}
Try It Yourself
See a 200 OK response in our request builder:
- Select GET method
- Set path to
/posts/1 - Click Send and observe the 200 response with post data
Try it with curl
curl -i https://api.example.com/items/42
Example output (illustrative, not captured from a real server):
HTTP/2 200
content-type: application/json
content-length: 41
{"id":42,"name":"Widget","price":9.99}
-i prints the status line and headers before the body. Add -o /dev/null -w '%{http_code}\n' to print only the status code.
Related Status Codes
- 201 Created - New resource created
- 204 No Content - Success with no body
- 304 Not Modified - Cached version is current
- 400 Bad Request - Request was invalid
- 500 Internal Server Error - Server failed
Related Concepts
- HTTP Methods - Request types
- Content-Type - Response format
- Caching - Storing responses
- 206 Partial Content - Only the requested byte range
See also the comparison 200 vs 201 vs 204: choosing the right success code for create, read, update and delete.
In practice
Express.js
// GET — return resource
app.get('/api/users/:id', async (req, res) => {
const user = await db.users.findById(req.params.id)
if (!user) return res.status(404).json({ error: 'Not found' })
res.status(200).json(user) // or just res.json(user)
})
// POST — action succeeded, return result
app.post('/api/search', async (req, res) => {
const results = await search(req.body.query)
res.json({ results, total: results.length })
// 200 is default — no need to set explicitly
})Next.js App Router
// app/api/users/[id]/route.ts
export async function GET(
_req: Request,
{ params }: { params: { id: string } }
) {
const user = await db.users.findById(params.id)
if (!user) return new Response(null, { status: 404 })
// Response.json() defaults to 200
return Response.json(user)
}Django
from django.http import JsonResponse
def user_detail(request, user_id):
try:
user = User.objects.get(pk=user_id)
# JsonResponse defaults to status=200
return JsonResponse(user.to_dict())
except User.DoesNotExist:
return JsonResponse({'error': 'Not found'}, status=404)Frequently asked questions
What does HTTP 200 OK mean?
HTTP 200 OK means the request was successful. The server understood the request, processed it correctly, and is returning the requested data. It is the standard success response for GET, POST, PUT, and other HTTP methods.
When should a server return 200 OK?
Return 200 OK when a request succeeds and you have content to return. For GET requests, return the requested resource. For POST/PUT, return the created or updated resource. Use 201 Created for new resources and 204 No Content when there is nothing to return.
What is the difference between 200 OK and 201 Created?
200 OK is a general success response. 201 Created specifically indicates a new resource was created, typically from a POST request. 201 should include a Location header pointing to the new resource.
Can a 200 response have an empty body?
Yes, but 204 No Content is more appropriate for successful requests with no response body. Use 200 OK when you have content to return, even if it is just a success message or empty array.
Does 200 OK mean there were no errors?
Not always. Some APIs return 200 OK with error details in the body. This is considered bad practice. Proper APIs use appropriate error status codes (4xx, 5xx) for errors and reserve 200 for actual success.
Sources
Related
200 vs 201 vs 204: Which Success Code to Return
Choose between 200 OK, 201 Created and 204 No Content for REST APIs: what each means, the Location and body rules, raw responses for POST, PUT, PATCH and DELETE.
304 Not Modified vs 200 OK
Understand when servers return 304 Not Modified instead of 200 OK. Learn how conditional requests, ETags, and Last-Modified headers enable efficient HTTP caching.
201 Created
Resource successfully created. Learn when to use 201 Created, proper response format, and best practices for creation endpoints.
202 Accepted
The request was accepted for processing but not completed yet. Learn when to use 202 for asynchronous operations.
203 Non-Authoritative Information
203 means a proxy modified the origin response before passing it on. Learn when it is sent, how it differs from 200, caching rules and what clients should do.
204 No Content
The request succeeded with no response body. Learn when to use 204 No Content for successful operations that don't return data.