Skip to main content

RequestInterceptor

Trait RequestInterceptor 

Source
pub trait RequestInterceptor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn pre_execute<'a>(
        &'a self,
        ctx: &'a mut RequestContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), ExecuteError>> + Send + 'a>>;
    fn post_execute<'a>(
        &'a self,
        ctx: &'a ResponseContext,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>;
}
Expand description

Async trait for request-level interceptors.

Interceptors run in the tokio async context (before compute pool dispatch), so they can perform async I/O (database lookups, network calls, etc.).

Multiple interceptors are chained: pre_execute runs in registration order, post_execute runs in reverse order (like middleware stacks).

Required Methods§

Source

fn pre_execute<'a>( &'a self, ctx: &'a mut RequestContext, ) -> Pin<Box<dyn Future<Output = Result<(), ExecuteError>> + Send + 'a>>

Called before query execution.

Return Ok(()) to allow the request to proceed. Return Err(ExecuteError) to reject the request. May mutate the context (e.g., set identity from API key lookup).

Source

fn post_execute<'a>( &'a self, ctx: &'a ResponseContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>

Called after query execution completes (success or failure).

This is called even if the execution failed, so interceptors can log failures and track usage regardless of outcome.

Implementors§