├── 200 ├── README.md ├── requirements.txt └── success.py ├── 302 ├── README.md ├── redirect.py └── requirements.txt ├── 404 ├── README.md ├── not_found.py └── requirements.txt ├── 502 ├── README.md ├── bad_gateway.py └── requirements.txt ├── LICENSE ├── README.md └── common-status-codes.md /200/README.md: -------------------------------------------------------------------------------- 1 | # Simulate 200 2 | 3 | ## Create virtual environment 4 | 5 | ```bash 6 | python3 -m venv myenv 7 | 8 | # Activate the virtual environment 9 | # On Windows 10 | myenv\Scripts\activate 11 | 12 | # On macOS/Linux 13 | source myenv/bin/activate 14 | ``` 15 | 16 | ## Install dependencies 17 | 18 | ```bash 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | ## Run the flask application 23 | 24 | ```bash 25 | python3 success.py 26 | ``` 27 | 28 | ### Verify using CURL 29 | 30 | ```bash 31 | curl -i http://127.0.0.1:5000/ 32 | ``` -------------------------------------------------------------------------------- /200/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.0.2 2 | requests==2.31.0 -------------------------------------------------------------------------------- /200/success.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, Response 2 | import requests 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def proxy_request(): 8 | # Use an endpoint that should return 200 OK with no delay 9 | upstream_url = 'https://httpbin.org/get' 10 | 11 | try: 12 | # Attempt to connect with a reasonable timeout 13 | response = requests.get(upstream_url, timeout=5) 14 | response.raise_for_status() # Raise an error for HTTP status codes 4xx/5xx 15 | 16 | # If successful, return the upstream response data as JSON with a 200 OK status 17 | return jsonify(response.json()), 200 18 | 19 | except requests.exceptions.RequestException as e: 20 | # Log the error (optional) 21 | app.logger.error(f"Upstream service error: {e}") 22 | 23 | # Return a 502 Bad Gateway error to the client if an exception occurs 24 | return Response("Bad Gateway: Could not connect to upstream service.", status=502) 25 | 26 | if __name__ == '__main__': 27 | app.run(debug=True) 28 | -------------------------------------------------------------------------------- /302/README.md: -------------------------------------------------------------------------------- 1 | # Simulate 302 - Redirect 2 | 3 | ## Create virtual environment 4 | 5 | ```bash 6 | python3 -m venv myenv 7 | 8 | # Activate the virtual environment 9 | # On Windows 10 | myenv\Scripts\activate 11 | 12 | # On macOS/Linux 13 | source myenv/bin/activate 14 | ``` 15 | 16 | ## Install dependencies 17 | 18 | ```bash 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | ## Run the flask application 23 | 24 | ```bash 25 | python3 redirect.py 26 | ``` 27 | 28 | ### Verify using CURL 29 | 30 | ```bash 31 | curl -i curl -i -L http://127.0.0.1:5000/ 32 | ``` -------------------------------------------------------------------------------- /302/redirect.py : -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, Response, redirect 2 | import requests 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def proxy_request(): 8 | # Use an endpoint on httpbin.org that issues a 302 redirect 9 | upstream_url = 'https://httpbin.org/redirect/1' 10 | 11 | try: 12 | # Allow redirects, but handle them manually for demonstration purposes 13 | response = requests.get(upstream_url, timeout=5, allow_redirects=False) 14 | 15 | # Check if the response status is 302 16 | if response.status_code == 302: 17 | redirect_url = response.headers.get("Location") 18 | app.logger.info(f"Redirecting to {redirect_url}") 19 | 20 | # Return a 302 Found response, redirecting the client to the new URL 21 | return redirect(redirect_url, code=302) 22 | 23 | # If successful (but not a 302), return the response JSON (if any) 24 | return jsonify(response.json()) 25 | 26 | except requests.exceptions.RequestException as e: 27 | # Log the error (optional) 28 | app.logger.error(f"Upstream service error: {e}") 29 | 30 | # Return a 502 Bad Gateway error to the client in case of other issues 31 | return Response("Bad Gateway: Could not connect to upstream service.", status=502) 32 | 33 | if __name__ == '__main__': 34 | app.run(debug=True) 35 | -------------------------------------------------------------------------------- /302/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.0.2 2 | requests==2.31.0 -------------------------------------------------------------------------------- /404/README.md: -------------------------------------------------------------------------------- 1 | # Simulate 404 - Not Found and Fix it 2 | 3 | ## Create virtual environment 4 | 5 | ```bash 6 | python3 -m venv myenv 7 | 8 | # Activate the virtual environment 9 | # On Windows 10 | myenv\Scripts\activate 11 | 12 | # On macOS/Linux 13 | source myenv/bin/activate 14 | ``` 15 | 16 | ## Install dependencies 17 | 18 | ```bash 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | ## Run the flask application 23 | 24 | ```bash 25 | python3 not_found.py 26 | ``` 27 | 28 | ### Verify using CURL 29 | 30 | ```bash 31 | curl -i http://127.0.0.1:5000/ 32 | ``` -------------------------------------------------------------------------------- /404/not_found.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, Response 2 | import requests 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def proxy_request(): 8 | # Use a non-existent path on httpbin.org to trigger a 404 9 | upstream_url = 'https://httpbin.org/status/404' 10 | 11 | try: 12 | # Attempt to connect with a reasonable timeout 13 | response = requests.get(upstream_url, timeout=5) 14 | response.raise_for_status() # Raise an error for HTTP status codes 4xx/5xx 15 | 16 | # If successful (unlikely in this setup), return the response 17 | return jsonify(response.json()) 18 | 19 | except requests.exceptions.HTTPError as e: 20 | if response.status_code == 404: 21 | # Log the error (optional) 22 | app.logger.error(f"Upstream service returned 404: {e}") 23 | 24 | # Return a 404 Not Found error to the client 25 | return Response("Not Found: The requested resource does not exist on the upstream service.", status=404) 26 | else: 27 | # For other errors, return a 502 Bad Gateway 28 | app.logger.error(f"Upstream service error: {e}") 29 | return Response("Bad Gateway: Could not connect to upstream service.", status=502) 30 | 31 | if __name__ == '__main__': 32 | app.run(debug=True) 33 | -------------------------------------------------------------------------------- /404/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.0.2 2 | requests==2.31.0 -------------------------------------------------------------------------------- /502/README.md: -------------------------------------------------------------------------------- 1 | # Simulate 502 - Bad Gateway and Fix it 2 | 3 | ## Create virtual environment 4 | 5 | ```bash 6 | python3 -m venv myenv 7 | 8 | # Activate the virtual environment 9 | # On Windows 10 | myenv\Scripts\activate 11 | 12 | # On macOS/Linux 13 | source myenv/bin/activate 14 | ``` 15 | 16 | ## Install dependencies 17 | 18 | ```bash 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | ## Run the flask application 23 | 24 | ```bash 25 | python3 bad_gateway.py 26 | ``` 27 | 28 | ### Verify using CURL 29 | 30 | ```bash 31 | curl -i http://127.0.0.1:5000/ 32 | ``` -------------------------------------------------------------------------------- /502/bad_gateway.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, jsonify, Response 2 | import requests 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def proxy_request(): 8 | # Upstream URL with a delay of 10 seconds 9 | upstream_url = 'https://httpbin.org/delay/10' 10 | 11 | try: 12 | # Attempt to connect with a 1-second timeout, forcing a timeout error 13 | response = requests.get(upstream_url, timeout=1) 14 | response.raise_for_status() # Raise an error for HTTP status codes 4xx/5xx 15 | 16 | # If successful (unlikely in this setup), return the response 17 | return jsonify(response.json()) 18 | 19 | except requests.exceptions.RequestException as e: 20 | # Log the error (optional) 21 | app.logger.error(f"Upstream service error: {e}") 22 | 23 | # Return a 502 Bad Gateway error to the client 24 | return Response("Bad Gateway: Could not connect to upstream service.", status=502) 25 | 26 | if __name__ == '__main__': 27 | app.run(debug=True) 28 | -------------------------------------------------------------------------------- /502/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.0.2 2 | requests==2.31.0 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTTP Status Codes 2 | 3 | ## 1. Informational Responses (100–199) 4 | 5 | - **100 Continue**: The initial part of a request has been received and the client can continue with the request. 6 | - **101 Switching Protocols**: The server is switching protocols as requested by the client. 7 | - **102 Processing**: The server has received and is processing the request, but no response is available yet (WebDAV). 8 | 9 | ## 2. Successful Responses (200–299) 10 | 11 | - **200 OK**: The request has succeeded. The meaning of the success depends on the HTTP method used. 12 | - **201 Created**: The request has succeeded and a new resource has been created as a result. 13 | - **202 Accepted**: The request has been accepted for processing, but the processing is not complete. 14 | - **203 Non-Authoritative Information**: The server successfully processed the request, but is returning information that may be from another source. 15 | - **204 No Content**: The server successfully processed the request, but is not returning any content. 16 | - **205 Reset Content**: The server successfully processed the request, and is asking the client to reset the document view. 17 | - **206 Partial Content**: The server is delivering only part of the resource due to a range header sent by the client. 18 | 19 | ## 3. Redirection Messages (300–399) 20 | 21 | - **300 Multiple Choices**: The request has more than one possible response, and the user or user agent should choose one. 22 | - **301 Moved Permanently**: The requested resource has been permanently moved to a new URL. 23 | - **302 Found**: The requested resource is temporarily located at a different URL, as specified in the Location header. 24 | - **303 See Other**: The response to the request can be found at another URI using a GET method. 25 | - **304 Not Modified**: The resource has not been modified since the last request, and the client can use the cached version. 26 | - **305 Use Proxy**: The requested resource must be accessed through the specified proxy. 27 | - **307 Temporary Redirect**: The requested resource is temporarily located at a different URL, and the client should use the original method for the next request. 28 | - **308 Permanent Redirect**: The requested resource has been permanently moved, and future requests should use the new URL provided (similar to 301 but for methods that are not allowed to change). 29 | 30 | ## 4. Client Error Responses (400–499) 31 | 32 | - **400 Bad Request**: The server cannot process the request due to a client error (e.g., malformed request syntax). 33 | - **401 Unauthorized**: Authentication is required and has failed or has not yet been provided. 34 | - **402 Payment Required**: Reserved for future use, but it is not widely used. 35 | - **403 Forbidden**: The server understands the request but refuses to authorize it. 36 | - **404 Not Found**: The requested resource could not be found on the server. 37 | - **405 Method Not Allowed**: The request method is not supported for the specified resource. 38 | - **406 Not Acceptable**: The server cannot produce a response matching the list of acceptable values defined in the request's headers. 39 | - **407 Proxy Authentication Required**: The client must authenticate itself with the proxy. 40 | - **408 Request Timeout**: The server timed out waiting for the request. 41 | - **409 Conflict**: The request could not be completed due to a conflict with the current state of the resource. 42 | - **410 Gone**: The resource requested is no longer available and no forwarding address is known. 43 | - **411 Length Required**: The server refuses to accept the request without a defined Content-Length. 44 | - **412 Precondition Failed**: The server does not meet one of the preconditions specified in the request headers. 45 | - **413 Payload Too Large**: The request entity is larger than limits defined by the server. 46 | - **414 URI Too Long**: The URI provided was too long for the server to process. 47 | - **415 Unsupported Media Type**: The media type of the request entity is not supported by the server. 48 | - **416 Range Not Satisfiable**: The range specified by the Range header field in the request cannot be satisfied. 49 | - **417 Expectation Failed**: The server cannot meet the requirements of the Expect request-header field. 50 | - **418 I'm a teapot**: An April Fools' joke; the server refuses to brew coffee because it is a teapot (RFC 2324). 51 | - **421 Misdirected Request**: The request was directed at a server that is not able to produce a response. 52 | - **422 Unprocessable Entity**: The request was well-formed but was unable to be followed due to semantic errors (WebDAV). 53 | - **423 Locked**: The resource that is being accessed is locked (WebDAV). 54 | - **424 Failed Dependency**: The request failed due to failure of a previous request (WebDAV). 55 | - **425 Too Early**: Indicates that the server is unwilling to risk processing a request that might be replayed. 56 | - **426 Upgrade Required**: The client should switch to a different protocol (e.g., TLS/1.0). 57 | - **428 Precondition Required**: The origin server requires the request to be conditional. 58 | - **429 Too Many Requests**: The user has sent too many requests in a given amount of time. 59 | - **431 Request Header Fields Too Large**: The server is unwilling to process the request because its header fields are too large. 60 | 61 | ## 5. Server Error Responses (500–599) 62 | 63 | - **500 Internal Server Error**: A generic error message indicating that the server encountered an unexpected condition. 64 | - **501 Not Implemented**: The server does not support the functionality required to fulfill the request. 65 | - **502 Bad Gateway**: The server was acting as a gateway or proxy and received an invalid response from the upstream server. 66 | - **503 Service Unavailable**: The server is currently unable to handle the request due to temporary overload or maintenance of the server. 67 | - **504 Gateway Timeout**: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. 68 | - **505 HTTP Version Not Supported**: The server does not support the HTTP protocol version used in the request. 69 | - **511 Network Authentication Required**: The client needs to authenticate to gain network access. 70 | 71 | 72 | -------------------------------------------------------------------------------- /common-status-codes.md: -------------------------------------------------------------------------------- 1 | # HTTP Status Codes 2 | 3 | ## 200 OK 4 | - **Meaning**: The request has succeeded. 5 | - **Usage**: The server returns this status code when the request was successfully processed and a valid response is available. The response will vary based on the HTTP method used. For example, in a `GET` request, the response body contains the requested resource; in a `POST` request, it may contain a confirmation message or the resource created. 6 | - **Example**: A successful API call to retrieve user data might return a `200 OK` status along with the user's information in JSON format. 7 | 8 | ## 201 Created 9 | - **Meaning**: The request has been fulfilled, and a new resource has been created as a result. 10 | - **Usage**: This status code is typically returned in response to a `POST` request when a new resource has been created on the server. The response usually includes a `Location` header containing the URL of the newly created resource. 11 | - **Example**: When a new user is registered through an API, the server returns a `201 Created` status along with the user’s details. 12 | 13 | ## 204 No Content 14 | - **Meaning**: The server has successfully processed the request, but is not returning any content. 15 | - **Usage**: This status code indicates that the server processed the request successfully, but there is no content to send back. It’s often used in response to `DELETE` requests or when a `PUT` request updates a resource without returning any information. 16 | - **Example**: After successfully deleting a resource, the server may respond with a `204 No Content` status. 17 | 18 | ## 301 Moved Permanently 19 | - **Meaning**: The requested resource has been permanently moved to a new URL. 20 | - **Usage**: This status code indicates that the resource has been moved permanently to a new location specified by the `Location` header. Clients should update their bookmarks and links to the new URL. 21 | - **Example**: A website might change its URL structure, causing an old URL to return a `301 Moved Permanently` status, redirecting users to the new URL. 22 | 23 | ## 302 Found 24 | - **Meaning**: The requested resource is temporarily located at a different URL. 25 | - **Usage**: This status code indicates that the resource is temporarily available at a different location specified by the `Location` header. Clients are expected to use the original URL for future requests. 26 | - **Example**: A web application might redirect users to a maintenance page temporarily, using a `302 Found` status to indicate the temporary change. 27 | 28 | ## 400 Bad Request 29 | - **Meaning**: The server cannot process the request due to a client error (e.g., malformed request syntax). 30 | - **Usage**: This status code is returned when the server cannot understand the request due to invalid syntax or parameters. It signifies that the client needs to modify the request before retrying. 31 | - **Example**: Sending a malformed JSON payload in a `POST` request may result in a `400 Bad Request` response. 32 | 33 | ## 401 Unauthorized 34 | - **Meaning**: Authentication is required and has failed or has not yet been provided. 35 | - **Usage**: This status code indicates that the request requires user authentication. It is commonly used in scenarios where API access requires authentication tokens or credentials. 36 | - **Example**: If a user attempts to access a protected resource without providing valid credentials, the server responds with a `401 Unauthorized` status. 37 | 38 | ## 403 Forbidden 39 | - **Meaning**: The server understands the request but refuses to authorize it. 40 | - **Usage**: This status code indicates that the server has determined that the client does not have permission to access the requested resource. Unlike a `401 Unauthorized` response, which indicates that authentication is required, a `403 Forbidden` response indicates that the server has rejected the request regardless of authentication. 41 | - **Example**: A user attempting to access an admin panel without the necessary privileges may receive a `403 Forbidden` status, indicating they are not allowed to view that resource. 42 | 43 | ## 404 Not Found 44 | - **Meaning**: The requested resource could not be found on the server. 45 | - **Usage**: This status code is returned when the server cannot find the requested resource. It may indicate that the resource has been deleted or that the URL was incorrect. 46 | - **Example**: A user trying to access a non-existent webpage will receive a `404 Not Found` response. 47 | 48 | ## 500 Internal Server Error 49 | - **Meaning**: A generic error message indicating that the server encountered an unexpected condition. 50 | - **Usage**: This status code is returned when the server encounters an unexpected condition that prevents it from fulfilling the request. It does not provide specific details about the error. 51 | - **Example**: A bug in the server code or an unhandled exception may trigger a `500 Internal Server Error` response. 52 | 53 | ## 502 Bad Gateway 54 | - **Meaning**: The server was acting as a gateway or proxy and received an invalid response from the upstream server. 55 | - **Usage**: This status code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. 56 | - **Example**: If a server is set up to proxy requests to another server and that upstream server is down or returns an error, the client may receive a `502 Bad Gateway` response. 57 | --------------------------------------------------------------------------------