OxL Reference

interface Middleware

The handler of a user attribute (attr Logged { … } + impl Middleware for Logged, then @Logged(…) on an rpc, §10.2): around wraps every call of the rpc on the server, in the order the attributes are written (the first one is outermost). It runs code before and after next(ctx), may refuse the call by returning Response.refuse(e) without calling next, and sees the context.

Example:

oxl✓ checked in CI
attr RequireUser {}

impl Middleware for RequireUser {
  fn around(ctx: &var Ctx, next: Next) -> Response net, io, time, db {
    match ctx.caller.userId() {
      str _ => next(ctx)
      AccessDenied _ => Response.refuse(AccessDenied{})
    }
  }
}

service Notes {
  @public @RequireUser rpc add(text: str) -> i64
}

impl Notes {
  rpc add(text) => 1
}
@explicit pub(api) interface Middleware

Since. 1.0.0-beta

Methods

around(ctx: &var Ctx, next: Next) -> Response net, io, time, db
Wraps every call of the rpc the attribute is written on

Defined in: std/core/rpc.oxl:525

See also