Expand description
Lifecycle hooks for extensibility
This module provides a comprehensive lifecycle hook system that allows extensions to hook into various lifecycle events in MockForge:
- Request/Response lifecycle: before_request, after_response
- Server lifecycle: on_startup, on_shutdown
- Mock lifecycle: on_mock_created, on_mock_updated, on_mock_deleted
§Examples
use mockforge_core::lifecycle::{LifecycleHook, RequestContext, ResponseContext};
use async_trait::async_trait;
struct LoggingHook;
#[async_trait]
impl LifecycleHook for LoggingHook {
async fn before_request(&self, ctx: &RequestContext) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
println!("Request: {} {}", ctx.method, ctx.path);
Ok(())
}
async fn after_response(&self, ctx: &ResponseContext) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
println!("Response: {} in {}ms", ctx.status_code, ctx.response_time_ms);
Ok(())
}
}Structs§
- Lifecycle
Hook Registry - Lifecycle hook registry
- Request
Context - Request context for lifecycle hooks
- Response
Context - Response context for lifecycle hooks
Enums§
- Mock
Lifecycle Event - Mock lifecycle event
- Server
Lifecycle Event - Server lifecycle event
Traits§
- Lifecycle
Hook - Comprehensive lifecycle hook trait