Response Status Codes
Cargo Condition
Section titled “Cargo Condition”Before you hand over the package, you need to declare its condition. This is the HTTP Status Code. It’s not just for errors—it’s the driver’s log of exactly what happened.
Fig 1: The Manifest. Everything accounted for.
The Ranges
Section titled “The Ranges”- 2xx (Success): Everything is smooth sailing.
200 OK: Standard success.201 Created: New resource made (like after a database insert).
- 3xx (Redirects): The resource moved. Rerouting.
301 Moved Permanently: It’s gone forever, update your bookmarks.302 Found: Temporary detour.
- 4xx (Client Error): You messed up.
400 Bad Request: You sent bad data.401 Unauthorized: Who are you? (Login needed)403 Forbidden: I know who you are, but you can’t come in.404 Not Found: Lost map.
- 5xx (Server Error): We messed up.
500 Internal Server Error: The truck exploded on the way.
Express Defaults vs Manual Override
Section titled “Express Defaults vs Manual Override”Express defaults to 200 if you don’t say anything. But if something goes wrong, or if you need to redirect traffic, you must be explicit.
// 301 Redirect (Moved permanently to the /things lane)// Useful for SEO when you change URL structuresapp.get('/old-things', (req, res) => { res.redirect(301, '/things');});
// 404 Not Found (Manual)app.get('/hidden-bunker', (req, res) => { res.status(404).send('File Not Found. Checked behind the couch. Nothing.');});Extra Bits & Bytes
Section titled “Extra Bits & Bytes”Express Status Codes - Demo Repo
MDN Status Codes