Receive and return the value of HTTP X-Request-ID header.
Project description
request-id-flask
Attach a unique identifier to every HTTP request in your WSGI application.
request-id-flask
is implemented as a WSGI middleware.
The package will do one of two things:
-
Read the
X-Request-ID
HTTP header from a client HTTP request and return the sameX-Request-ID
HTTP header in the server HTTP response and is stored in the WSGIenviron
. -
Or, when no
X-Request-ID
HTTP header is present in the client HTTP request, generate a new and uniquerequest_id
identifier (using uuid 4) which is stored in the WSGIenviron
and set as theX-Request-ID
HTTP header in the server HTTP responser.
Requirements
- Python 3.6 or above
Installation
You can install the request-id-flask package using pip:
pip install flask-ext-request-id
However, recommended to add it to the requirements.txt
file instead.
Access the request_id
The REQUEST_ID
is stored in the request environ
dictionary and may be accessed from anywhere this is available in Flask.
Usage
from flask import (
Flask,
request
)
from request_id import RequestId
app = Flask(__name__)
RequestId(app)
@app.route('/')
def index():
request_id = request.environ.get('REQUEST_ID', '')
return str(request_id)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for request_id_flask-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6902a709005c9136a2fe58f4086fc434fdb499b6fb68b537398212dcf95047c7 |
|
MD5 | de653192c6a9db6d050a159bf9acd2fe |
|
BLAKE2b-256 | 448fc6afa5df7398edc7070d6653f170b062eec2abaf94d5a91a1ec322b0ed60 |