HTTP middleware for web applications (imperative shell).
This namespace provides reusable HTTP middleware that can be used across different modules and applications. It follows RFC standards and best practices for web API development.
Middleware functions handle I/O boundaries: request/response interception, logging, and exception handling.
Features:
Multi-Tenant Middleware: See wagoe.tenant.shell.tenant-middleware for:
HTTP middleware for web applications (imperative shell). This namespace provides reusable HTTP middleware that can be used across different modules and applications. It follows RFC standards and best practices for web API development. Middleware functions handle I/O boundaries: request/response interception, logging, and exception handling. Features: - Request correlation ID management - Tenant and user context extraction - Multi-tenant request processing with schema switching - Structured request/response logging with observability context - RFC 7807 Problem Details for error responses (via core) - Generic exception handling middleware - Error reporting breadcrumb integration Multi-Tenant Middleware: See wagoe.tenant.shell.tenant-middleware for: - Tenant resolution (subdomain, JWT, headers) - PostgreSQL schema switching per request - Tenant caching with configurable TTL - Combined middleware for simplified integration
(wrap-correlation-id handler)Middleware to add correlation ID to requests and responses.
Adds a unique correlation ID to each request for tracing purposes. Uses X-Correlation-ID header if present, otherwise generates a new UUID.
Args: handler: Ring handler function
Returns: Ring middleware function
Middleware to add correlation ID to requests and responses. Adds a unique correlation ID to each request for tracing purposes. Uses X-Correlation-ID header if present, otherwise generates a new UUID. Args: handler: Ring handler function Returns: Ring middleware function
(wrap-exception-handling handler)(wrap-exception-handling handler error-mappings)Middleware to catch exceptions and return RFC 7807 problem details with context.
SHELL FUNCTION: Performs side effects (exception catching, logging). Uses pure core functions for problem details transformation with enhanced context.
Catches all exceptions and converts them to standardized RFC 7807 problem details responses with full error context for debugging. Logs exceptions for debugging and monitoring, and reports them to the error reporting system.
Args: handler: Ring handler function error-mappings: Optional custom error type mappings
Returns: Ring middleware function
Middleware to catch exceptions and return RFC 7807 problem details with context. SHELL FUNCTION: Performs side effects (exception catching, logging). Uses pure core functions for problem details transformation with enhanced context. Catches all exceptions and converts them to standardized RFC 7807 problem details responses with full error context for debugging. Logs exceptions for debugging and monitoring, and reports them to the error reporting system. Args: handler: Ring handler function error-mappings: Optional custom error type mappings Returns: Ring middleware function
(wrap-observability-context handler)(wrap-observability-context handler _logger)Middleware to create observability context from request data.
Builds a structured context map that can be used by logging, metrics, and error reporting throughout the request lifecycle. This middleware should run after correlation-id, tenant-context, and user-context middleware.
Args: handler: Ring handler function logger: ILogger instance (optional, for context enhancement)
Returns: Ring middleware function
Middleware to create observability context from request data. Builds a structured context map that can be used by logging, metrics, and error reporting throughout the request lifecycle. This middleware should run after correlation-id, tenant-context, and user-context middleware. Args: handler: Ring handler function logger: ILogger instance (optional, for context enhancement) Returns: Ring middleware function
(wrap-request-logging handler)(wrap-request-logging handler logger)Middleware for structured request/response logging with observability context.
Logs HTTP requests and responses with timing information, correlation IDs, and enriched context for observability and debugging purposes. Also adds error reporting breadcrumbs for request lifecycle tracking.
This middleware should run after wrap-observability-context to have access to the full observability context.
Args: handler: Ring handler function logger: ILogger instance (optional, uses tools.logging if not provided)
Returns: Ring middleware function
Middleware for structured request/response logging with observability context. Logs HTTP requests and responses with timing information, correlation IDs, and enriched context for observability and debugging purposes. Also adds error reporting breadcrumbs for request lifecycle tracking. This middleware should run after wrap-observability-context to have access to the full observability context. Args: handler: Ring handler function logger: ILogger instance (optional, uses tools.logging if not provided) Returns: Ring middleware function
(wrap-tenant-context handler)Middleware to extract and add tenant context to requests.
Extracts tenant ID from various sources (header, JWT, query param) and adds it to the request context for downstream observability and business logic.
Extraction priority:
Args: handler: Ring handler function
Returns: Ring middleware function
Middleware to extract and add tenant context to requests. Extracts tenant ID from various sources (header, JWT, query param) and adds it to the request context for downstream observability and business logic. Extraction priority: 1. X-Tenant-Id header (explicit tenant override) 2. :tenant-id from JWT claims (if JWT middleware ran first) 3. tenant-id query parameter Args: handler: Ring handler function Returns: Ring middleware function
(wrap-user-context handler)Middleware to extract and add user context to requests.
Extracts user ID from various sources (JWT claims, session) and adds it to the request context for downstream observability and audit logging.
Extraction priority:
Args: handler: Ring handler function
Returns: Ring middleware function
Middleware to extract and add user context to requests. Extracts user ID from various sources (JWT claims, session) and adds it to the request context for downstream observability and audit logging. Extraction priority: 1. :user-id from JWT claims (if JWT middleware ran first) 2. :user-id from session (if session middleware ran first) 3. X-User-Id header (for service-to-service calls) Args: handler: Ring handler function Returns: Ring middleware function
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |