The simple version
Imagine you’re ordering food at a restaurant. The waiter tells you whether your order was taken, if the kitchen can’t make it, or if the kitchen ran out of ingredients. In the same way, a REST API sends a status code—a short number that tells you what happened when you asked a server to do something.
- 200 = “All good, here’s your dish.”
- 401 = “You’re not allowed to order this dish.”
- 500 = “The kitchen has a major problem.”
These codes are the first thing you’ll look at when debugging a web request. They’re like a quick cheat sheet that lets you know whether you need to check your request, your credentials, or the server itself.
What the numbers actually mean
Status codes are grouped into five families, each one a ten‑point scale that gives you a rough idea of the outcome:
| Family | Meaning |
|---|---|
| 1xx | Informational – the request is being processed. |
| 2xx | Success – the request worked. |
| 3xx | Redirection – you need to do something else. |
| 4xx | Client error – something was wrong with your request. |
| 5xx | Server error – the server failed to do what you asked. |
So when you see 200, you’re in the 2xx family, meaning the server did what you asked and sent back data.
401 is in the 4xx family—your request was understood but rejected because of authentication.
500 lives in the 5xx family, telling you that the server itself encountered an unexpected problem.
Common codes and their everyday meaning
| Code | Quick explanation | When you’ll see it |
|---|---|---|
| 200 OK | The request succeeded. | Fetching a list of posts, posting a comment. |
| 201 Created | Your request created a new resource. | Creating a new user or article. |
| 204 No Content | Success, but nothing to return. | Deleting a resource. |
| 400 Bad Request | The server couldn’t understand the request. | Sending malformed JSON. |
| 401 Unauthorized | You’re not logged in or your token is invalid. | Accessing a protected endpoint without a token. |
| 403 Forbidden | You’re logged in but don’t have permission. | Trying to delete someone else’s post. |
| 404 Not Found | The requested resource doesn’t exist. | Requesting a user ID that isn’t in the database. |
| 500 Internal Server Error | Something went wrong on the server. | A bug in the backend code. |
| 502 Bad Gateway | The server acting as a gateway received an invalid response. | Your API depends on another service that’s down. |
These are the codes you’ll encounter most often in everyday development.
Reading the response: headers, body, and status
A full HTTP response looks like this:
HTTP/1.1 200 OK
Content-Type: application/json
X-RateLimit-Remaining: 99
{ "id": 42, "title": "Hello World" }
- Status line (
HTTP/1.1 200 OK) tells you the code and a short text. - Headers (e.g.,
Content-Type,X-RateLimit-Remaining) give extra context. - Body contains the data or an error message.
When you get a 401, the body often contains something like:
{ "error": "Invalid token", "message": "Authentication credentials were not provided." }
That tells you why the request failed. A 500 might return a generic message:
{ "error": "Internal Server Error", "message": "An unexpected error occurred." }
In both cases, the status code is the first clue; the body gives more detail.
When to look deeper: errors vs. success
Success (2xx): If you get a 200 or 201, check the body to make sure the data matches what you expect. A 204 means the action succeeded but there’s no data to return, so you’ll need to verify by another request.
Client errors (4xx): These usually mean you sent something wrong. A 400 could be a typo in your JSON. A 401 means you need to log in or refresh your token. A 403 tells you you’re authenticated but lack permission. A 404 means the resource doesn’t exist—double‑check the ID.
Server errors (5xx): These are on the server side. A 500 means something broke on the backend. If you’re the developer, check server logs. If you’re a consumer of the API, retry after a short wait or contact the API provider.
A quick debugging tip
Use curl or Postman to see the raw response. For example:
curl -i -H "Authorization: Bearer <token>" https://api.example.com/posts/1
The -i flag prints headers and the body, so you can immediately spot the status code and any error message.
What to try next
Play with a public API – use
curlor Postman to hit endpoints likehttps://jsonplaceholder.typicode.com/posts/1. Observe the status codes for GET, POST, PUT, and DELETE requests.Add error handling to your app – write a small function that logs the status code and prints a friendly message (e.g., “Oops! You need to log in.” for 401).
Experiment with authentication – create a simple token, send it in the
Authorizationheader, and intentionally send a bad token to see a 401 response. Then fix it and verify you get a 200.
By understanding what 200, 401, and 500 really mean, you’ll be better equipped to diagnose problems quickly and write clearer, more resilient code. Happy debugging!
FAQ
What does a 200 status code mean in a REST API?
A 200 status code indicates the request succeeded and the server returned the requested data in the response body.
Why do I get a 401 Unauthorized error?
A 401 error means your request was understood but rejected due to missing or invalid authentication credentials, such as an expired token.
What should I check when I receive a 500 Internal Server Error?
A 500 error signals a server-side problem; check server logs, retry after a short wait, or contact the API provider for details.
How can I inspect the raw response of an API call?
Use curl with the -i flag or Postman to print headers and body, allowing you to see the status code and any error message directly.