OK
Production Risk
None. This is the desired outcome for most successful read operations.
The request has succeeded. The meaning of the success depends on the HTTP method: GET requests will have the resource in the body, HEAD requests will have headers, and POST requests will have a result of the action.
- 1A client successfully requested a webpage.
- 2An API call to fetch data completed successfully.
- 3A form submission was processed without errors.
A user successfully navigates to the homepage of a website.
curl https://example.com
expected output
HTTP/1.1 200 OK
Fix
Return 200 with the appropriate response body for GET requests
// Express — correct use of 200 OK for a GET endpoint
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: 'User not found' });
}
// 200 is the default status — res.json() implies it
res.json(user);
});
// Client-side: check for 200 before parsing the body
const response = await fetch('/api/users/42');
if (response.ok) { // response.ok is true for 200–299
const user = await response.json();
}Why this works
200 OK is the correct status for successful GET, POST, PUT, and PATCH requests that return a body. Use it when the resource was found and the response body contains the requested data. For resource creation use 201, for no body use 204. On the client side, response.ok covers all 2xx codes, so a 200 is handled automatically by any correct success branch.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev