Flask Request ID Header

0.1.1 · maintenance · verified Thu Apr 16

Flask-Request-ID-Header is a Python Flask middleware designed to ensure that all incoming requests to a Flask application include an `X-Request-ID` header, containing at least one unique value. This is particularly useful for request tracing and correlation in distributed systems and logging. The current version is 0.1.1, and the project has not seen active development since its last release in March 2019, indicating a maintenance-only status.

Common errors

Warnings

Install

Imports

Quickstart

Initializes a Flask app and applies the RequestID middleware. It then defines a simple route to demonstrate how to retrieve the `X-Request-ID` header from the request.

from flask import Flask, request
from flask_request_id_header.middleware import RequestID

app = Flask(__name__)
RequestID(app)

@app.route('/')
def hello_world():
    request_id = request.headers.get('X-Request-ID', 'No-Request-ID-Found')
    return f'Hello, world! Request ID: {request_id}'

if __name__ == '__main__':
    app.run(debug=True)

view raw JSON →