Full Configuration Example

Updated Jul 20, 2026
import falcon
from falcon_correlate import CorrelationIDMiddleware


def custom_generator() -> str:
    import uuid

    return str(uuid.uuid4())


def custom_validator(value: str) -> bool:
    # Accept any non-empty string up to 64 characters
    return bool(value) and len(value) <= 64


middleware = CorrelationIDMiddleware(
    header_name="X-Request-ID",
    trusted_sources=["10.0.0.0/8", "192.168.0.0/16"],
    generator=custom_generator,
    validator=custom_validator,
    echo_header_in_response=True,
)

app = falcon.App(middleware=[middleware])