0
0
Rest-apiConceptBeginner · 3 min read

What Are HTTP Status Codes: Simple Explanation and Examples

HTTP status codes are three-digit numbers sent by a web server to a client to indicate the result of a request. They tell you if the request was successful, if there was an error, or if further action is needed, using codes like 200 for success or 404 for not found.
⚙️

How It Works

Imagine you send a letter to a friend asking for information. The HTTP status code is like the reply your friend sends back to tell you what happened with your letter. It could say "I got your letter and here is the answer" or "I can't find what you asked for" or "Please wait, I need more time."

When your web browser or app asks a server for a webpage or data, the server responds with a status code. This code quickly tells your browser if the request worked, if there was a problem, or if something else is going on. This helps your browser decide what to do next, like showing the page, showing an error message, or trying again.

💻

Example

This example shows a simple Python script that makes a web request and prints the HTTP status code returned by the server.
python
import requests

response = requests.get('https://httpbin.org/status/404')
print(f'Status code: {response.status_code}')
Output
Status code: 404
🎯

When to Use

HTTP status codes are used anytime a client (like a browser or app) talks to a server over the web. They are essential for web developers and API creators to communicate clearly about what happened with a request.

For example, use 200 when a request is successful and the server sends back the requested data. Use 404 when the requested page or resource does not exist. Use 500 when the server has an error it cannot handle. This helps users and developers understand and fix problems quickly.

Key Points

  • HTTP status codes are three-digit numbers sent by servers to describe request results.
  • They are grouped by their first digit: 1xx (informational), 2xx (success), 3xx (redirection), 4xx (client errors), 5xx (server errors).
  • Common codes include 200 (OK), 404 (Not Found), and 500 (Internal Server Error).
  • They help browsers and apps decide how to handle responses.

Key Takeaways

HTTP status codes tell clients if a web request succeeded or failed.
They use three-digit numbers grouped by type of response.
Common codes like 200, 404, and 500 are important to know.
Servers send these codes with every response to guide client behavior.