DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

What is Status Code?

When frontend calls backend, server responds with:

Status Code + Response
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ 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
Enter fullscreen mode Exit fullscreen mode

```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
Enter fullscreen mode Exit fullscreen mode

```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
Enter fullscreen mode Exit fullscreen mode

```http id="d4bf3k"
Server overloaded β†’ 503




---

# πŸ”₯ WHAT YOU SHOULD USE IN YOUR API

### Your current backend:

#### GET



```js id="tj9xjs"
res.json(users);
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Returns:

200 OK
Enter fullscreen mode Exit fullscreen mode

POST

```js id="hcn8wp"
res.status(201).json(newUser);




πŸ‘‰ Correct:



```id="kxj6h8"
201 Created
Enter fullscreen mode Exit fullscreen mode

PUT

```js id="c3yo0x"
res.json(user);




πŸ‘‰ Should be:



```id="h9n83j"
200 OK
Enter fullscreen mode Exit fullscreen mode

DELETE

Right now:

```js id="bzgk4x"
res.send("User deleted");




πŸ‘‰ Better (production):



```js id="2p5b6q"
res.status(204).send();
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)