API Fundamentals
/Beginner
Most Common Status Codes
Definition
A cheat sheet of the absolute must-know HTTP status codes that every web developer will encounter on a daily basis.
Explain Like I'm New
There are dozens of status codes, but you only memorize about 10 of them. 200 = OK. 201 = Created. 301 = Moved. 400 = Bad Request. 401 = Not Logged In. 403 = Not Allowed. 404 = Not Found. 500 = Server Blew Up.
Real World Example
When writing an API client using Axios or Fetch, you write `if (response.status === 404) { showNotFoundUI() }`.
Common Use Cases
- •Frontend error handling
- •Backend API design
Terminal Output
bash / terminal
/*
The Developer's Cheat Sheet:
SUCCESS (2xx):
200 OK: Everything worked.
201 Created: You POSTed data, and it was successfully saved.
204 No Content: You DELETEd data successfully.
CLIENT ERRORS (4xx) - "It's the Frontend's fault"
400 Bad Request: You sent invalid JSON or missing fields.
401 Unauthorized: You forgot to send your Auth Token.
403 Forbidden: You sent an Auth Token, but you aren't an Admin.
404 Not Found: The URL is wrong, or the DB item doesn't exist.
429 Too Many Requests: You hit the API too fast. Rate limited.
SERVER ERRORS (5xx) - "It's the Backend's fault"
500 Internal Server Error: The backend code crashed entirely.
503 Service Unavailable: The server is down for maintenance.
*/
Interview Questions
basic
- What is the famous status code for a page or resource that does not exist?
intermediate
- What is a `429 Too Many Requests` code used for?