Skip to content

Commit

Permalink
clarification on usage in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Mar 3, 2019
1 parent a09e1e7 commit 87cde15
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Expand Up @@ -4,6 +4,59 @@ Plug-able webhook handler. Primary use case is to sync GitHub issues and Version

> WARNING: under heavy development; not for production use.
## Usage

```shell
npm install @andrew-codes/webhooked
```

### Example

Example using with Azure Functions:

```js
const webhooked = require('andrew-codes/webhooked');

module.exports = async function(context, req) {
try {
const responses = await webhooked({
presets: [],
plugins: ['@andrew-codes/webhooked-plugin-example'],
}).handle(req);
context.log(responses);
context.res = { status: 200 };
} catch (errors) {
context.log(errors);
context.res = { status: 500 };
}
};
```

### Config Object

Configuration accepts an array of presets and plugins. Plugin modules are **async** functions that accept a request object. They are responsible handling/doing something with each received webhook request. Although they receive every request, they are not required to act upon it.

Presets are several plugins packaged into a single module. Both may accept options like the below:

```js
webhooked({
presets: [
'webhooked-preset-example',
[
'webhooked-preset-with-options',
{
option: 'values',
},
],
],
plugins: [
'webhooked-plugin-1',
[('webhooked-plugin-with-options', { option: 'value' })],
'webooked-plugin-another-one',
],
});
```

## Running Locally

- install node@>=10.15.1
Expand Down

0 comments on commit 87cde15

Please sign in to comment.