> For the complete documentation index, see [llms.txt](https://mandarineframework.gitbook.io/mandarine-ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-core/components/middleware.md).

# Middleware

## Concepts

* It is part of the Mandarine MVC module.
* It works as an interceptor for HTTP requests made to a *mandarine endpoint.*
* It accepts the use of DI, however, this type of component is not injectable.

## Usage

**Syntax:**

```typescript
@Middleware(regexRoute: RegExp)
```

* regexRoute
  * Regular expression of HTTP endpoint url to intercept.

Example

```typescript
import { Middleware, MiddlewareTarget } from "https://deno.land/x/mandarinets/mod.ts";

@Middleware(new RegExp('/api/*'))
export class Middleware1 implements MiddlewareTarget {

    // To be executed on pre-request of a request which url matches the middleware's regular expression route
    public onPreRequest(@ResponseParam() response: any): boolean {
        /**
         * True = the request must continue, 
         * False = the request will stop 
         */
        return true;
    }
    
    // To be executed on post-request of a request which url matches the middleware's regular expression route
    public onPostRequest(): void {
    }
}
```
