├── wsgi.py ├── requirements.txt ├── .gitignore ├── README.md └── app.py /wsgi.py: -------------------------------------------------------------------------------- 1 | from app import app 2 | if __name__ == '__main__': 3 | app.run() 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | blinker==1.9.0 2 | click==8.2.1 3 | Flask==3.1.1 4 | gunicorn==23.0.0 5 | itsdangerous==2.2.0 6 | Jinja2==3.1.6 7 | MarkupSafe==3.0.2 8 | packaging==25.0 9 | Werkzeug==3.1.3 10 | wheel==0.45.1 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Python bytecode and virtual environment 2 | __pycache__/ 3 | *.pyc 4 | .venv/ 5 | venv/ 6 | 7 | # Instance folder (for configuration, databases, etc.) 8 | instance/ 9 | 10 | # Flask-related generated files 11 | .flaskenv 12 | 13 | # Test-related files 14 | .pytest_cache/ 15 | .coverage 16 | htmlcov/ 17 | 18 | # Distribution and build files 19 | dist/ 20 | build/ 21 | *.egg-info/ 22 | 23 | # Editor-specific files (examples) 24 | .idea/ 25 | .vscode/ 26 | *.swp 27 | *~ 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Flask Status Code Responder 2 | This project is a straightforward Flask application designed to respond with HTTP status codes based on the path parameter provided. By passing a valid status code as part of the URL path, the application returns the corresponding HTTP response with that status code. 3 | 4 | ## Features 5 | ### Dynamic Status Code Response: 6 | The app extracts the first three digits from the URL path and attempts to match them to a list of predefined valid HTTP status codes. 7 | ### Supported Status Codes: 8 | The application recognizes and responds with the following status codes: 9 | * 200: OK 10 | * 201: Created 11 | * 400: Bad Request 12 | * 401: Unauthorized 13 | * 403: Forbidden 14 | * 404: Not Found 15 | * 500: Internal Server Error 16 | * 502: Bad Gateway 17 | * 503: Service Unavailable 18 | ### Fallback Handling: 19 | If an invalid status code is provided or the format doesn't match, the application defaults to returning a 404 Not Found status. 20 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, abort, make_response 2 | import re 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/', methods=['GET', 'PUT', 'POST']) 7 | def return_status(subpath): 8 | # Use regex to extract the first three digits 9 | match = re.match(r'^(\d{3})', subpath) 10 | if match: 11 | status_code = int(match.group(1)) 12 | 13 | # Define valid status codes and their messages 14 | valid_status_codes = { 15 | 200: "OK", 16 | 201: "Created", 17 | 400: "Bad Request", 18 | 401: "Unauthorized", 19 | 403: "Forbidden", 20 | 404: "Not Found", 21 | 500: "Internal Server Error", 22 | 502: "Bad Gateway", 23 | 503: "Service Unavailable" 24 | } 25 | 26 | # Check if the status code is valid 27 | if status_code in valid_status_codes: 28 | message = valid_status_codes[status_code] 29 | return make_response(message, status_code) 30 | 31 | # If the status code is not valid or no match, return 404 32 | abort(404) 33 | 34 | if __name__ == "__main__": 35 | app.run(host='0.0.0.0') 36 | --------------------------------------------------------------------------------