Page Contents

Home > @loopback/rest > RestApplication > middleware

RestApplication.middleware() method

Register a middleware function or provider class

Signature:

middleware(middleware: Middleware | Constructor<Provider<Middleware>>, options?: MiddlewareBindingOptions): Binding<Middleware>;

Parameters

Parameter Type Description
middleware Middleware | Constructor<Provider<Middleware>> Middleware function or provider class
options MiddlewareBindingOptions (Optional) Middleware binding options

Returns:

Binding<Middleware>

Example

const log: Middleware = async (requestCtx, next) {
  // ...
}
server.middleware(log);