DEV Community

Vidyarathna Bhat
Vidyarathna Bhat

Posted on

Understanding the Basics of HTTP Status Codes

When developing web applications, understanding HTTP status codes is essential for effectively managing client-server communication. These codes, sent by the server in response to a client's request, are part of the HTTP protocol and indicate whether a request was successful, if an error occurred, or if further actions are needed. Here’s an overview of HTTP status codes and their significance.

1. Informational Responses (100-199)

Informational responses indicate that the request was received and understood, and that the process is continuing.

  • 100 Continue: The initial part of a request has been received and the client can continue with the rest of the request.
  • 101 Switching Protocols: The server is switching protocols as requested by the client.
  • 102 Processing: The server has received and is processing the request, but no response is available yet.

2. Successful Responses (200-299)

Successful responses indicate that the request was successfully received, understood, and accepted.

  • 200 OK: The request has succeeded. The meaning of the success depends on the HTTP method (GET, POST, etc.).
  • 201 Created: The request has been fulfilled and has resulted in the creation of a new resource.
  • 202 Accepted: The request has been accepted for processing, but the processing has not been completed.
  • 204 No Content: The server successfully processed the request, but is not returning any content.

3. Redirection Messages (300-399)

Redirection messages indicate that further action needs to be taken by the client in order to complete the request.

  • 301 Moved Permanently: The requested resource has been permanently moved to a new URL.
  • 302 Found: The requested resource resides temporarily under a different URL.
  • 304 Not Modified: Indicates that the resource has not been modified since the version specified by the request headers.

4. Client Error Responses (400-499)

Client error responses indicate that there was a problem with the request.

  • 400 Bad Request: The server could not understand the request due to invalid syntax.
  • 401 Unauthorized: The client must authenticate itself to get the requested response.
  • 403 Forbidden: The client does not have access rights to the content.
  • 404 Not Found: The server cannot find the requested resource.
  • 429 Too Many Requests: The user has sent too many requests in a given amount of time.

5. Server Error Responses (500-599)

Server error responses indicate that the server failed to fulfill a valid request.

  • 500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
  • 502 Bad Gateway: The server, while acting as a gateway or proxy, received an invalid response from the upstream server.
  • 503 Service Unavailable: The server is not ready to handle the request. Common causes are server overload or maintenance.
  • 504 Gateway Timeout: The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.

HTTP status codes play a crucial role in web development and API design by providing essential information about the result of a client's request. By familiarizing yourself with these codes, you can better handle responses and ensure robust and reliable web applications. Understanding these codes is key for effective development and troubleshooting.

Top comments (6)

tracygjg profile image
Tracy Gilmore

Oh no, Vidyarathna, you missed the most important status code: HTTP/418.

vidyarathna profile image
Vidyarathna Bhat • Edited

Haha, you're right! I guess I missed the opportunity to include the HTTP/418 - 'I'm a teapot' status code. Thanks for the reminder!

tonyltf profile image
Tony Li

Should I use HTTP 422 for invalid POST body?

vidyarathna profile image
Vidyarathna Bhat

Yes, using HTTP 422 for an invalid POST body is appropriate. HTTP 422 (Unprocessable Entity) indicates that the server understands the request but cannot process it due to semantic errors or failed validation within the request body. This status code provides a specific indication of the issue, enhancing clarity for client applications.

jitendrachoudhary profile image
Jitendra Choudhary

Nice one!!

vidyarathna profile image
Vidyarathna Bhat

Thank you!!