Skip to main content

Command Palette

Search for a command to run...

Activity 30: HTTP Status Codes

Published
9 min readView as Markdown
Activity 30: HTTP Status Codes
B

SMILING EVERYDAY FOR GOODIE.

HTTP Status Codes in RESTful APIs:

RESTful APIs rely on HTTP status codes to communicate the outcome of a client's request to the server. These codes provide valuable information about the success or failure of the request, allowing clients to understand the server's response and take appropriate actions. Let's delve into the various HTTP status codes categorized by their class and explore their usage in RESTful APIs.

1xx (Informational):

These codes indicate that the request has been received and is being processed, but the server has not yet completed the request.

  • 100 Continue: The server has received the initial part of a request and asks the client to continue sending the rest of the request. This is often used for large uploads.

  • 101 Switching Protocols: The server is switching to a different protocol as requested by the client. This is typically used for upgrading the connection from HTTP to a more efficient protocol like WebSockets.

  • 102 Processing (WebDAV): The server has received the request and is processing it, but no response is available yet. This code is specific to the WebDAV protocol and indicates that the server is still working on the request.

  • 103 Early Hints: The server is sending hints to the client about resources that might be needed for the final response. This allows the client to start preloading resources while the server prepares the full response, potentially improving performance.

2xx (Success): Request Completed Successfully

These codes indicate that the request was successful and the server has completed the requested action.

  • 200 OK: The request was successful, and the server returned the requested data. This is the most common success code and indicates that the request was processed without any errors.

  • 201 Created: The request was successful, and a new resource was created as a result. This code is typically used after a POST request to create a new resource, and the response often includes the URL of the newly created resource.

  • 202 Accepted: The request was accepted for processing, but the server has not yet completed the action. This code is often used for requests that require

  • 203 Non-Authoritative Information: The server returned information that may not be the definitive set as available from the origin server. This code indicates that the information was retrieved from a local or third-party copy.

  • 204 No Content: The request was successful, but there is no content to send in the response. This code is often used for requests that modify a resource but do not return any data, such as a DELETE request.

  • 205 Reset Content: The server is asking the client to reset the document view. This code is often used for requests that modify a resource and require the client to refresh the view.

  • 206 Partial Content: The server is returning only a portion of the requested resource. This code is often used for requests that specify a range of data to be retrieved, such as a request for a specific part of a large file.

3xx (Redirection): Further Action Required

These codes indicate that the client must take additional actions to complete the request.

  • 300 Multiple Choices: The requested resource has multiple representations available, each with its own URL. The client can choose which representation to retrieve.

  • 301 Moved Permanently: The requested resource has been permanently moved to a new URL. The client should update its bookmarks and future requests should use the new URL.

  • 302 Found: The requested resource has been temporarily moved to a new URL. The client should use the new URL for this request, but future requests may still use the original URL.

  • 303 See Other: The server is redirecting the client to a different URL to complete the request. The client should use a GET request to the new URL.

  • 304 Not Modified: The client can use its cached copy of the requested resource. The server is indicating that the resource has not been modified since the last request.

  • 307 Temporary Redirect: The server is redirecting the client to a different URL to complete the request. The client should use the same HTTP method for the new URL.

  • 308 Permanent Redirect: The server is redirecting the client to a different URL to complete the request. The client should use the same HTTP method for the new URL. This code is similar to 307 but indicates a permanent redirect.

4xx (Client Error): Request Issues

These codes indicate that the client's request was invalid or cannot be processed.

  • 400 Bad Request: The request was invalid or cannot be understood by the server. This code is often used for requests with invalid syntax, missing parameters, or incorrect data.

  • 401 Unauthorized: Authentication is required for the requested resource. The client must provide valid credentials to access the resource.

  • 403 Forbidden: The client does not have permission to access the resource, even if they are authenticated. This code is often used for resources that require specific permissions or roles.

  • 404 Not Found: The requested resource could not be found. This is a common error when the client requests a resource that does not exist.

  • 405 Method Not Allowed: The requested method is not allowed for the specified resource. This code is often used when the client attempts to use an inappropriate HTTP method for the resource, such as using a PUT request for a resource that only allows GET requests.

  • 406 Not Acceptable: The server cannot produce a response that the client can accept. This code is often used when the client requests a resource in a format that the server does not support.

  • 408 Request Timeout: The client did not send a request within the time allowed by the server. This code is often used when the client is slow to respond or the server has a short timeout limit.

  • 409 Conflict: The request could not be completed because of a conflict with the current state of the resource. This code is often used for requests that attempt to modify a resource that is already being modified by another client.

  • 410 Gone: The requested resource is no longer available and will not be available again. This code is often used for resources that have been permanently deleted.

  • 411 Length Required: The server requires a content length header for the request. This code is often used for requests that require the server to know the size of the request body before processing it.

  • 412 Precondition Failed: The server could not fulfill the request because one or more of the preconditions given in the request headers evaluated to false. This code is often used for requests that require specific conditions to be met before processing.

  • 413 Payload Too Large: The request body is too large for the server to process. This code is often used for requests with large uploads that exceed the server's limits.

  • 414 URI Too Long: The request URL is too long for the server to process. This code is often used for requests with very long URLs that exceed the server's limits.

  • 415 Unsupported Media Type: The request body is in a format that the server does not support. This code is often used for requests with incorrect content types.

  • 416 Range Not Satisfiable: The client requested a range of data that is not available. This code is often used for requests that specify a range of data that is outside the bounds of the resource.

  • 417 Expectation Failed: The server could not fulfill the request because one or more of the expectations given in the request headers evaluated to false. This code is often used for requests that require specific conditions to be met before processing.

  • 418 I'm a teapot: This code is a humorous response and is not intended for use in production.

  • 422 Unprocessable Entity: The server understands the request but cannot process it because of invalid data. This code is often used for requests that contain invalid data, such as missing or incorrect fields.

  • 423 Locked: The requested resource is locked. This code is often used for resources that are currently being modified by another client.

  • 424 Failed Dependency: The request could not be completed because it depends on another request that failed. This code is often used for requests that require a specific sequence of operations to be completed.

  • 425 Too Early: The server is not ready to handle the request. This code is often used for requests that are sent before the server is ready to process them.

  • 426 Upgrade Required: The server requires the client to upgrade to a different protocol. This code is often used for requests that require a more efficient protocol, such as WebSockets.

  • 428 Precondition Required: The server requires the client to include a precondition header in the request. This code is often used for requests that require specific conditions to be met before processing.

  • 429 Too Many Requests: The client has sent too many requests in a short period of time. This code is often used to prevent denial-of-service attacks.

  • 431 Request Header Fields Too Large: The request header fields are too large for the server to process. This code is often used for requests with very large headers that exceed the server's limits.

  • 451 Unavailable For Legal Reasons: The server is unable to provide the requested resource due to legal reasons. This code is often used for resources that are blocked by government censorship or other legal restrictions.

5xx (Server Error): Server-Side Issues

These codes indicate that the server encountered an error and could not complete the request.

  • 500 Internal Server Error: The server encountered an unexpected error and could not complete the request. This is a generic error code that is often used when the server cannot provide more specific information about the error.

  • 501 Not Implemented: The server does not support the requested functionality. This code is often used for requests that require features that are not yet implemented by the server.

  • 502 Bad Gateway: The server received an invalid response from an upstream server.

  • 503 Service Unavailable: The server is temporarily unavailable, often due to maintenance or overload.

  • 504 Gateway Timeout: The server did not receive a response from an upstream server within the time allowed.

  • 505 HTTP Version Not Supported: The server does not support the HTTP version used in the request.

  • 506 Variant Also Negotiates: The server is requesting the client to use a different variant of the resource.

  • 507 Insufficient Storage: The server does not have enough storage space to complete the request.

  • 508 Loop Detected: The server detected an infinite loop while processing the request.

  • 510 Not Extended: The server is refusing to fulfill the request because it does not support the request extension.

  • 511 Network Authentication Required: The client needs to authenticate with a proxy server to access the requested resource.

More from this blog

Bacia, John Ruzzel A.'s blog

42 posts