Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/idiocc/compose

Compose a single middleware function for Goa out of many.
https://github.com/idiocc/compose

compose goa idio middleware

Last synced: about 2 months ago
JSON representation

Compose a single middleware function for Goa out of many.

Awesome Lists containing this project

README

        

# @goa/compose

[![npm version](https://badge.fury.io/js/%40goa%2Fcompose.svg)](https://www.npmjs.com/package/@goa/compose)

`@goa/compose` is Compose a single middleware function for Goa out of many.

```sh
yarn add @goa/compose
```

## Table Of Contents

- [Table Of Contents](#table-of-contents)
- [API](#api)
- [`compose(middleware: !Array): !Function`](#composemiddleware-arrayfunction-function)
- [Copyright & License](#copyright--license)



## API

The package is available by importing its default function:

```js
import compose from '@goa/compose'
```



## compose(
  `middleware: !Array,`
): !Function
Compose a single middleware function for Goa out of many.

- middleware* !Array<!Function>: The array with the middleware.

```js
import Goa from '@goa/koa'
import rqt from 'rqt'
import compose from '@goa/compose'

const goa = new Goa()

const composed = compose([
async (ctx, next) => {
ctx.body = 'hello'
await next()
},
async (ctx) => {
ctx.body += ' world'
},
])

goa.use(composed)

goa.listen(async function() {
const url = `http://127.0.0.1:${this.address().port}`
const res = await rqt(url)
console.log(res)
this.close()
})
```
```
hello world
```



## Copyright & License

GNU Affero General Public License v3.0

[Original work](https://www.npmjs.com/package/koa-compose) by dead-horse under MIT license. Copy of the license is not included as not found in the original package.


idiocc
© Art Deco™ 2019