HTTP status codes are standard response codes sent by a server to indicate the result of a client request. They are grouped into five categories: informational, success, redirection, client error, and server error.
An HTTP response starts with a status line containing the protocol version, status code, and reason phrase.
HTTP/1.1 200 OK
// Example HTTP response status line
HTTP/1.1 404 Not Found
// Fetch API handling HTTP status codes
fetch("/api/users")
.then(response => {
if(response.status === 200){
console.log("Success");
}else if(response.status === 404){
console.log("Not Found");
}
});
A 200 status means the request succeeded, while 404 indicates the requested resource was not found on the server.
// Simulated HTTP status checker
function checkStatus(code){
if(code >= 200 && code < 300){
return "Success";
}
if(code >= 400 && code < 500){
return "Client Error";
}
if(code >= 500){
return "Server Error";
}
return "Other";
}
Try it: Enter a Status Code (e.g., 200, 404, 503)