How truelayer/reqwest-middleware works
Main Components
a) Core Components:
• reqwest-middleware (Core Library)
• reqwest-retry (Retry Middleware)
• reqwest-tracing (Tracing Middleware)
• External reqwest Client
b) Integration Points:
• Third-party Middleware Support
• Client Builder Interface
• Middleware Chain
┌─ Application Layer ─────────────────────────┐
• Client Application Code │
• ┬───────────────────────┘
• ↓
┌─ Middleware Chain Layer ────────────────────┐
• ┌─────────────┐ ┌─────────────┐ ┌──────┐ │
• Tracing │→ │ Retry │→ │ More │ │
• Middleware │ │ Middleware │ │ ... │ │
• ┘ └─────────────┘ └──────┘ │
• ┬───────────────────────┘
• ↓
┌─ Core Layer ──────────────────────────────┐
• ┌─────────────────────────────────────┐ │
• ClientWithMiddleware │ │
• ┌─────────────┐ ┌──────────────┐ │ │
• Middleware │ │ Request │ │ │
• Manager │ │ Pipeline │ │ │
• ┘ └──────────────┘ │ │
• ┘ │
• ┬───────────────────────┘
• ↓
┌─ Base Layer ──────────────────────────────┐
• Reqwest HTTP Client │
• ┘
Important Elements to Highlight
a) Core Functionality:
• ClientBuilder pattern
• Middleware Chain execution flow
• Request/Response pipeline
b) Extension Points:
• Custom middleware integration
• Third-party middleware support
• Configuration options
Additional Details
┌─ Middleware Component ──────────────────┐
• ┌──────────────┐ ┌──────────────┐ │
• Request │ → │ Middleware │ │
• Interceptor │ │ Logic │ │
• ┘ └──────────────┘ │
• ↓ ↓ │
• ┌──────────────┐ ┌──────────────┐ │
• Response │ ← │ Error │ │
• Handler │ │ Handler │ │
• ┘ └──────────────┘ │
• ┘
Key Relationships
• How the ClientBuilder constructs the middleware chain
• How requests flow through the middleware pipeline
• How each middleware component interacts with the core client
• Integration points for third-party middleware
• Error handling and retry flows
Notes for Implementation Details
• How the retry policy is configured
• Tracing integration points
• Extension points for custom middleware
• Error handling paths