@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
184 lines (86 loc) • 3.31 kB
Markdown
---
lang: en
title: 'API docs: rest.middlewaresequence'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/rest
permalink: /doc/en/lb4/apidocs.rest.middlewaresequence.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/rest](./rest.md) > [MiddlewareSequence](./rest.middlewaresequence.md)
## MiddlewareSequence class
A sequence implementation using middleware chains
**Signature:**
```typescript
export declare class MiddlewareSequence implements SequenceHandler
```
**Implements:** [SequenceHandler](./rest.sequencehandler.md)
## Constructors
<table><thead><tr><th>
Constructor
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
[(constructor)(context, invokeMiddleware, options)](./rest.middlewaresequence._constructor_.md)
</td><td markdown="1">
</td><td markdown="1">
Constructor: Injects `InvokeMiddleware` and `InvokeMiddlewareOptions`
</td></tr>
</tbody></table>
## Properties
<table><thead><tr><th>
Property
</th><th>
Modifiers
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
[defaultOptions](./rest.middlewaresequence.defaultoptions.md)
</td><td markdown="1">
`static`
</td><td markdown="1">
InvokeMiddlewareOptions
</td><td markdown="1">
</td></tr>
<tr><td markdown="1">
[invokeMiddleware](./rest.middlewaresequence.invokemiddleware.md)
</td><td markdown="1">
`readonly`
</td><td markdown="1">
InvokeMiddleware
</td><td markdown="1">
</td></tr>
<tr><td markdown="1">
[options](./rest.middlewaresequence.options.md)
</td><td markdown="1">
`readonly`
</td><td markdown="1">
InvokeMiddlewareOptions
</td><td markdown="1">
</td></tr>
</tbody></table>
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td markdown="1">
[handle(context)](./rest.middlewaresequence.handle.md)
</td><td markdown="1">
</td><td markdown="1">
Runs the default sequence. Given a handler context (request and response), running the sequence will produce a response or an error.
Default sequence executes these groups of middleware:
- `cors`<!-- -->: Enforces `CORS` - `openApiSpec`<!-- -->: Serves OpenAPI specs - `findRoute`<!-- -->: Finds the appropriate controller method, swagger spec and args for invocation - `parseParams`<!-- -->: Parses HTTP request to get API argument list - `invokeMethod`<!-- -->: Invokes the API which is defined in the Application controller method
In front of the groups above, we have a special middleware called `sendResponse`<!-- -->, which first invokes downstream middleware to get a result and handles the result or error respectively.
- Writes the result from API into the HTTP response (if the HTTP response has not been produced yet by the middleware chain. - Catches error logs it using 'logError' if any of the above steps in the sequence fails with an error.
</td></tr>
</tbody></table>