# Middleware

# What is a middleware ?

A middleware is a class that implement MiddlewareInterface. This interface have a single imposed method :

  process(params: ParamsType, context: ContextType, next?: Function, options?: any):Promise<ResultType>;
1

# How to use it

  • Step 1 : add a binding to your service provider :
@Container.serviceProvider({
  middlewares: [
    ['can', PermissionMiddleware],
  ],
})
1
2
3
4
5
  • Step 2 : add this middleware to your actions :
readonly middlewares: (string|[string, any])[] = [
  ['can', ['user.list']]
];
1
2
3

That's all! You can create your own middleware, find how