Urgent.News

What's breaking now, across thousands of outlets.

Tech

HTTP Status Codes

You send a request to an API. Sometimes everything works: 200 OK Sometimes you made a mistake: 404 Not Found And sometimes the problem isn't yours at all: 500 Internal Server Error These three-digit numbers are HTTP status codes. They are one of the simplest ways for a server to tell a client what happened to its request. But with dozens of possible status codes, do you really need to memorize…

HTTP status codes are three-digit numbers that a server uses to inform a client about the outcome of a request. These codes are divided into five categories: informational (1xx), success (2xx), redirection (3xx), client error (4xx), and server error (5xx). Understanding these codes and knowing when to use them is essential for backend developers.

The most common HTTP status codes include:

1. 200 OK: Indicates that the request was successfully processed. For example, a GET request returning user data.

2. 201 Created: Used when a new resource is created successfully in a POST request. For example, creating a new user.

3. 204 No Content: Returned when the server successfully processes a request but has nothing to send back, such as a DELETE operation.

4. 301 Moved Permanently and 302 Found: Indicate that the requested resource has been moved to a different location. The client should follow the new location for future requests.

5. 400 Bad Request: Indicates that the server cannot process the request due to an invalid request format. For example, malformed JSON or missing required fields.

6. 401 Unauthorized: Returned when the client needs to authenticate or if the provided authentication credentials are invalid.

7. 403 Forbidden: Indicates that the client is authenticated but does not have permission to access the requested resource.

8. 404 Not Found: Indicates that the requested resource could not be found on the server. For example, requesting a non-existent user.

9. 405 Method Not Allowed: Indicates that the client used an HTTP method that the server does not support for the requested resource.

10. 429 Too Many Requests: Returned when the client has exceeded the rate limit or sent too many requests in a given period, typically associated with rate limiting.

11. 500 Internal Server Error: Indicates a server-side error that occurred while processing the request. For example, an unexpected exception or database error.

12. 502 Bad Gateway: Indicates that a server received an invalid response from an upstream server it was trying to access.

Understanding HTTP status codes and their meanings is crucial for backend developers to troubleshoot issues, design effective APIs, and ensure smooth communication between clients and servers.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Monday 14 September →