---
lang: en
title: 'API docs: rest.restapplication.middleware'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/loopback-next/tree/master/packages/rest
permalink: /doc/en/lb4/apidocs.rest.restapplication.middleware.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/rest](./rest.md) &gt; [RestApplication](./rest.restapplication.md) &gt; [middleware](./rest.restapplication.middleware.md)

## RestApplication.middleware() method

Register a middleware function or provider class

<b>Signature:</b>

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

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  middleware | [Middleware](./express.middleware.md) \| [Constructor](./context.constructor.md)<!-- -->&lt;[Provider](./context.provider.md)<!-- -->&lt;[Middleware](./express.middleware.md)<!-- -->&gt;&gt; | Middleware function or provider class |
|  options | [MiddlewareBindingOptions](./express.middlewarebindingoptions.md) | Middleware binding options |

<b>Returns:</b>

[Binding](./context.binding.md)<!-- -->&lt;[Middleware](./express.middleware.md)<!-- -->&gt;

## Example


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

```


