Module lifecycle

Module lifecycle 

Source
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§

LifecycleHookRegistry
Lifecycle hook registry
RequestContext
Request context for lifecycle hooks
ResponseContext
Response context for lifecycle hooks

Enums§

MockLifecycleEvent
Mock lifecycle event
ServerLifecycleEvent
Server lifecycle event

Traits§

LifecycleHook
Comprehensive lifecycle hook trait