200 OK
An HTTP status code indicating that a request has succeeded and the server has returned the requested data.
Overview
200 OK is the most common HTTP status code, indicating that the request was successful and the server is returning the expected response. When you load a web page or fetch data from an API successfully, you typically receive a 200 status code. It's the standard response for successful HTTP requests.
Example
javascript// Fetch API response fetch('https://api.example.com/users') .then(response => { console.log(response.status); // 200 console.log(response.ok); // true return response.json(); }) .then(data => console.log(data)); // Axios example axios.get('/api/users') .then(response => { console.log(response.status); // 200 console.log(response.data); }); // Check status explicitly async function fetchData() { const response = await fetch('/api/data'); if (response.status === 200) { const data = await response.json(); return data; } throw new Error('Request failed'); } // Express.js server sending 200 app.get('/api/users', (req, res) => { res.status(200).json({ users: [] }); });
Key Points
- Indicates successful HTTP request
- Most common status code
- response.ok is true for 200-299 range
- Default status code for successful responses
- Part of 2xx success status codes
Learn More
- 404 Error - Not found error
- Fetch - Fetch API
- MDN: HTTP Status 200