Combined Middleware and Routes - Flask Typing CST Test
Loading…
Combined Middleware and Routes — Flask Code
Combines logging, JSON POST, and routes in Flask.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.before_request
def log_request():
print(f'{request.method} {request.path}')
@app.route('/')
def index():
return jsonify({ 'message': 'Welcome' })
@app.route('/echo', methods=['POST'])
def echo():
return jsonify(request.json)
if __name__ == '__main__':
app.run(debug=True, port=5000)Flask Language Guide
Flask is a lightweight, WSGI-based web framework for Python. It emphasizes simplicity, flexibility, and minimalism, allowing developers to build web applications and APIs quickly without imposing a specific project structure.
Primary Use Cases
- ▸RESTful API development
- ▸Backend for web/mobile applications
- ▸Microservices architecture
- ▸Prototyping and MVP development
- ▸Serving dynamic web content using templates
Notable Features
- ▸Lightweight and minimalistic core
- ▸Extensible via Flask extensions
- ▸Built-in development server and debugger
- ▸URL routing and request handling
- ▸Jinja2 template engine for rendering HTML
Origin & Creator
Flask was created by Armin Ronacher in 2010 as part of the Pocoo project, aiming to provide a simple and extensible Python web framework.
Industrial Note
Flask is preferred for projects requiring flexibility, lightweight architecture, or microservices without the overhead of larger frameworks like Django.