Expand description
Request-level interceptors for pre/post query execution hooks.
This module provides an async interceptor mechanism that allows consumers to hook into the request lifecycle — before and after query execution. Interceptors can reject requests (for auth, rate limiting, credit checks) or observe results (for logging, billing, usage tracking).
§Example
ⓘ
use reifydb::server;
struct MyInterceptor;
impl RequestInterceptor for MyInterceptor {
fn pre_execute(&self, ctx: &mut RequestContext)
-> Pin<Box<dyn Future<Output = Result<(), ExecuteError>> + Send + '_>>
{
Box::pin(async move {
if ctx.metadata.get("authorization").is_none() {
return Err(ExecuteError::Rejected {
code: "AUTH_REQUIRED".into(),
message: "Missing API key".into(),
});
}
Ok(())
})
}
fn post_execute(&self, ctx: &ResponseContext)
-> Pin<Box<dyn Future<Output = ()> + Send + '_>>
{
Box::pin(async move {
tracing::info!(duration_ms = ctx.duration.as_millis(), "query executed");
})
}
}
let db = server::memory()
.with_request_interceptor(MyInterceptor)
.build()?;Structs§
- Request
Context - Context available to pre-execute interceptors.
- Request
Interceptor Chain - Ordered chain of request interceptors, cheap to clone (Arc internally).
- Request
Metadata - Protocol-agnostic metadata extracted from the request transport layer.
- Response
Context - Context available to post-execute interceptors.
Enums§
- Operation
- The type of database operation being executed.
- Protocol
- The transport protocol used for the request.
Traits§
- Request
Interceptor - Async trait for request-level interceptors.