viewof statusCategory = Inputs.radio(["2xx Success", "4xx Client Error", "5xx Server Error"], {value: "4xx Client Error", label: "Status category"})
viewof iotScenario = Inputs.select([
"Sensor sends valid reading",
"New device registration",
"Command acknowledged (no body)",
"Malformed sensor payload",
"Expired API key",
"Device offline / unregistered",
"Too many requests (burst)",
"Server maintenance window",
"Device did not respond"
], {value: "Malformed sensor payload", label: "IoT scenario"})HTTP Status Code Explorer
HTTP Status Code Explorer
animation
http
app-protocols
Try Choose an IoT scenario and change Status category to match. Then press Check status category.
Observe After pressing Check status category, watch the code and category feedback as Status category changes.
Explain Explain why Status category matches the first digit of the code after you press Check status category.
Technical boundaries. Each listed scenario maps to a fixed code, action and response body. The category check compares the selected category with that mapping.
NoteTry It: HTTP Status Code Explorer
{
const codeMap = {
"Sensor sends valid reading": {code: 200, text: "OK", category: "2xx Success", action: "Return sensor data in response body", response: '{"temperature": 23.5, "humidity": 61}'},
"New device registration": {code: 201, text: "Created", category: "2xx Success", action: "Return device ID and provisioning details", response: '{"device_id": "d-0042", "status": "active"}'},
"Command acknowledged (no body)": {code: 204, text: "No Content", category: "2xx Success", action: "No response body needed", response: "(empty body)"},
"Malformed sensor payload": {code: 400, text: "Bad Request", category: "4xx Client Error", action: "Return validation errors so device can fix payload", response: '{"error": "Invalid field: temp must be number"}'},
"Expired API key": {code: 401, text: "Unauthorized", category: "4xx Client Error", action: "Prompt device to refresh credentials", response: '{"error": "API key expired", "action": "re-auth"}'},
"Device offline / unregistered": {code: 404, text: "Not Found", category: "4xx Client Error", action: "Log missing device, alert fleet manager", response: '{"error": "Device not found", "device_id": "d-99"}'},
"Too many requests (burst)": {code: 429, text: "Too Many Requests", category: "4xx Client Error", action: "Include Retry-After header, client backs off", response: '{"error": "Rate limit exceeded", "retry_after": 30}'},
"Server maintenance window": {code: 503, text: "Service Unavailable", category: "5xx Server Error", action: "Include Retry-After header with maintenance ETA", response: '{"error": "Maintenance", "retry_after": 3600}'},
"Device did not respond": {code: 504, text: "Gateway Timeout", category: "5xx Server Error", action: "Gateway retries with exponential backoff", response: '{"error": "Device timeout", "timeout_ms": 30000}'}
};
const info = codeMap[iotScenario];
const isCorrectCategory = info.category === statusCategory;
const catColor = statusCategory === "2xx Success" ? "#16A085" : statusCategory === "4xx Client Error" ? "#E67E22" : "#E74C3C";
return html`
<div style="font-family: Arial, sans-serif; padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid ${catColor};">
<p style="margin-top: 0; margin-bottom: 0.8em; color: #2C3E50; font-weight: 700; font-size: 1.1em;">HTTP Status Code for IoT</p>
<div style="display: grid; grid-template-columns: auto 1fr; gap: 15px; margin: 15px 0; align-items: start;">
<div style="background: white; padding: 15px 25px; border-radius: 6px; border: 2px solid ${catColor}; text-align: center;">
<div style="font-size: 2.2em; font-weight: bold; color: ${catColor};">${info.code}</div>
<div style="font-size: 0.9em; color: #7F8C8D;">${info.text}</div>
</div>
<div style="background: white; padding: 15px; border-radius: 6px;">
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 4px;">Scenario</div>
<div style="font-weight: bold; color: #2C3E50; margin-bottom: 10px;">${iotScenario}</div>
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 4px;">Recommended Action</div>
<div style="color: #2C3E50; margin-bottom: 10px;">${info.action}</div>
<div style="font-size: 0.85em; color: #7F8C8D; margin-bottom: 4px;">Example Response Body</div>
<code style="display: block; background: #2C3E50; color: #16A085; padding: 8px 12px; border-radius: 4px; font-size: 0.85em; word-break: break-all;">${info.response}</code>
</div>
</div>
<div style="background: ${isCorrectCategory ? '#e8f5e9' : '#fff3e0'}; padding: 10px 15px; border-radius: 6px; font-size: 0.9em;">
${isCorrectCategory
? html`<span style="color: #16A085;"><strong>Correct!</strong> Status ${info.code} belongs to ${statusCategory}.</span>`
: html`<span style="color: #E67E22;"><strong>Note:</strong> Status ${info.code} actually belongs to <strong>${info.category}</strong>, not ${statusCategory}. The first digit determines the category.</span>`
}
</div>
</div>
`;
}