# 文章
## middleware 中间件
> 正是因为中间件的扩展性才使得 `Koa` 的代码简单灵活。
在 `app.js` 中,有这样一段代码:
```js
app.use(async (ctx, next)=>{
await next()
ctx.response.type = \'text/html\'
ctx.response.body = \'Hello World\'
})
```
它的作用是:每收到一个 `http` 请求,`Koa` 都会调用通过 `app.use()` 注册的 `async` 函数,同时为该函数传入 `ctx` 和 `next` 两个参数。而这个 `async` 函数就是我们所说的中间件。
中间件用法——讲解 Koa2 中间件的用法及如何开发中间件