Senior
What are the types of HTTP response codes?
sobes.tech AI
Answer from AI
HTTP status codes are divided into five classes based on the first digit of the code:
- 1xx (Informational) — the request has been received, and the process is continuing (e.g., 100 Continue).
- 2xx (Success) — the request was successfully received, understood, and accepted (e.g., 200 OK, 201 Created).
- 3xx (Redirection) — further action is needed to complete the request (e.g., 301 Moved Permanently, 302 Found).
- 4xx (Client Error) — there was an error on the client side (e.g., 400 Bad Request, 401 Unauthorized, 404 Not Found).
- 5xx (Server Error) — there was an error on the server side (e.g., 500 Internal Server Error, 503 Service Unavailable).
In Go, working with HTTP codes typically involves using constants from the net/http package, for example:
import "net/http"
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound) // 404
w.Write([]byte("Page not found"))
}