When frontend calls backend, server responds with:
Status Code + Response
π Status code tells:
- success
- error
- what happened
β 1xx β Informational (Rare)
| Code | Meaning |
|---|---|
| 100 | Continue |
| 101 | Switching Protocols |
π Usually not used in your API testing
β 2xx β SUCCESS (Most Important)
| Code | Meaning | When used |
|---|---|---|
| 200 | OK | GET success |
| 201 | Created | POST success |
| 202 | Accepted | Request accepted (async) |
| 204 | No Content | Success but no response body |
π₯ Examples
```http id="hwl2wr"
GET /users β 200 OK
```http id="tsmz92"
POST /users β 201 Created
```http id="21npr6"
DELETE /users/4 β 204 No Content
---
# β
3xx β REDIRECTION
| Code | Meaning |
| ---- | -------------------------- |
| 301 | Moved Permanently |
| 302 | Found (temporary redirect) |
| 304 | Not Modified |
π Mostly browser-related, not common in API testing
---
# β
4xx β CLIENT ERRORS (VERY IMPORTANT)
π Problem from **user/request side**
| Code | Meaning | Example |
| ---- | -------------------- | ------------------ |
| 400 | Bad Request | Missing JSON field |
| 401 | Unauthorized | No login/token |
| 403 | Forbidden | No permission |
| 404 | Not Found | Wrong URL or ID |
| 405 | Method Not Allowed | Wrong HTTP method |
| 409 | Conflict | Duplicate data |
| 422 | Unprocessable Entity | Validation failed |
---
### π₯ Examples
```http id="33rrv1"
GET /users/999 β 404 Not Found
```http id="9flkqn"
POST without body β 400 Bad Request
---
# β
5xx β SERVER ERRORS (VERY IMPORTANT)
π Problem from **backend/server**
| Code | Meaning |
| ---- | --------------------- |
| 500 | Internal Server Error |
| 502 | Bad Gateway |
| 503 | Service Unavailable |
| 504 | Gateway Timeout |
---
### π₯ Examples
```http id="2lm9mt"
Database crash β 500
```http id="d4bf3k"
Server overloaded β 503
---
# π₯ WHAT YOU SHOULD USE IN YOUR API
### Your current backend:
#### GET
```js id="tj9xjs"
res.json(users);
π Returns:
200 OK
POST
```js id="hcn8wp"
res.status(201).json(newUser);
π Correct:
```id="kxj6h8"
201 Created
PUT
```js id="c3yo0x"
res.json(user);
π Should be:
```id="h9n83j"
200 OK
DELETE
Right now:
```js id="bzgk4x"
res.send("User deleted");
π Better (production):
```js id="2p5b6q"
res.status(204).send();
π₯ INTERVIEW ANSWERS (IMPORTANT)
β What status code for POST?
201 Created
β What status code if user not found?
404 Not Found
β What status code for server error?
500 Internal Server Error
β What status code for successful GET?
200 OK
π₯ DEVOPS VIEW
You monitor APIs using status codes:
- 200 β healthy
- 4xx β client issue
- 5xx β system failure (critical alert)
π₯ QUICK CHEAT SHEET
200 β OK
201 β Created
204 β No Content
400 β Bad Request
401 β Unauthorized
403 β Forbidden
404 β Not Found
500 β Server Error
Top comments (0)