> For the complete documentation index, see [llms.txt](https://tofishes.gitbook.io/maty-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tofishes.gitbook.io/maty-js/master.md).

# Maty.js 简介

### 安装

```bash
$ npm install maty
```

{% hint style="info" %}
&#x20;Maty.js requires **node v8.0** or higher
{% endhint %}

### 功能

* Router config 简单配置即可实现接口数据的获取及页面渲染，甚至接口代理等
* Filters request/response 过滤器，可以自定义请求的处理和响应，扩展功能
* Interceptors 拦截器，可用作公共请求处理等
* ctx.forward 服务器端跳转，例如同一个路由地址，可以根据不同的参数转到不同的页面
* emplate engine 默认使用[nunjucks](https://mozilla.github.io/nunjucks/)模板引擎，支持多引擎同时使用
* Auto render 在无路由配置的情况下，自动渲染和请求路径一致的模板文件

### 工作流程示意图

![maty workflow](/files/-LPz45l3Zs7wpbekKCt-)

使用代码描述工作流程，如下：

```javascript
const app = maty();

// middleware
app.use(async (ctx, next) => {
  await next();
});

// filter
app.filter('request', async (ctx, next) => {
  // before request handler
  await next();
  // after request handler
});

// filter
app.filter('response', async (ctx, next) => {
  // before response handler
  await next();
  // after response handler
});

// middleware
app.use(async (ctx, next) => {
  await next();
});

app.listen();
```
