Response Methods
Understanding Server Feedback
You've learned about HTTP request methods, which tell the server what action the client wants to perform. Now, let's look at how the server communicates the result of that request back to the client. This is done through HTTP response status codes - three-digit numbers that indicate whether the request was successful, and if not, what went wrong.
Think of it like a conversation:
- Client: "Can I have this web page?" (Sends an HTTP request with the GET method)
- Server: "Sure, here it is!" (Sends an HTTP response with a
200 OK
status code) - Or, Server: "I can't find that page." (Sends an HTTP response with a
404 Not Found
status code)
The status code is the server's concise way of saying what happened.
Categories of Status Codes
HTTP status codes are grouped into five categories, based on the first digit:
-
1xx (Informational): These codes indicate that the request was received and the server is continuing to process it. You don't usually see these codes directly in your browser.
- Example:
100 Continue
.
- Example:
-
2xx (Successful): These codes mean that the request was successful. The server received the request, understood it, and processed it without any problems.
- Example:
200 OK
(the most common success code),201 Created
(for successful resource creation),204 No Content
(successful request, but no content to return).
- Example:
-
3xx (Redirection): These codes indicate that the client needs to take additional action to complete the request. The requested resource has moved, either temporarily or permanently.
- Example:
301 Moved Permanently
,302 Found
(temporary redirect),307 Temporary Redirect
,308 Permanent Redirect
.
- Example:
-
4xx (Client Error): These codes indicate that there was a problem with the client's request. The request might be malformed, unauthorized, or the requested resource might not exist.
- Example:
400 Bad Request
,401 Unauthorized
,403 Forbidden
,404 Not Found
(the most famous error code!),405 Method Not Allowed
.
- Example:
-
5xx (Server Error): These codes indicate that there was a problem on the server's side. The server failed to fulfill a valid request.
- Example:
500 Internal Server Error
,502 Bad Gateway
,503 Service Unavailable
,504 Gateway Timeout
.
- Example:
Last updated on