rent
Learn by example

11. Policies, interceptors, and hooks

Use each layer for a distinct responsibility:

  • Policies decide whether an entity operation is allowed and can enforce predicates.
  • Interceptors observe or rewrite queries before and after execution.
  • Hooks observe or rewrite mutations and receive before, after, and error stages.
let client = Client::new(pool)
    .with_policy(policy)
    .with_interceptors(interceptors)
    .with_hooks(hooks);

The example hides rows through both a policy and an interceptor, rewrites Ada to Ada Lovelace through a hook, and rejects a forbidden mutation.

Middleware needs only one generated entity in crates/rent/examples/tutorial_10_middleware/schema.rsl. Run cargo run -p rent --example tutorial_10_middleware. The same middleware workflow runs under nextest.