<commit_before># bragg-router [![Build Status](https://travis-ci.org/SamVerschueren/bragg-router.svg?branch=master)](https://travis-ci.org/SamVerschueren/bragg-router)

> Router middleware for [bragg](https://github.com/SamVerschueren/bragg).


## Install

```
$ npm install --save bragg-router
```


## Usage

```js
const app = require('bragg')();
const router = require('bragg-router')();

router.get('/', ctx => {
    ctx.body = 'Home';
});

router.get('/user/{id}', ctx => {
    ctx.body = `Retrieve user with id ${ctx.request.params.id}`;
});

app.use(router.routes());

exports.handler = app.listen();
```

### Multiple handlers

When a handler returns a promise, that promise will be resolved first. The result of following example will be `Foo Bar`.

```js
const app = require('bragg')();
const router = require('bragg-router')();

router.get('/',
	() => Promise.resolve('Foo');
	(ctx, result) => {
    	ctx.body = `${result} Bar`;
	}
);

app.use(router.routes());

exports.handler = app.listen();
```

## Mapping template

In order for you to use the router, you will have to add extra properties to your [mapping template](https://github.com/SamVerschueren/bragg#mapping-template).

```json
{
    "resource-path": "$context.resourcePath",
    "http-method": "$context.httpMethod"
}
```

[Bragg](https://github.com/SamVerschueren/bragg) will detect these properties and expose them as `path` and `method` properties in the middlewares.


## API<commit_msg>tweak docs<commit_after># bragg-router [![Build Status](https://travis-ci.org/SamVerschueren/bragg-router.svg?branch=master)](https://travis-ci.org/SamVerschueren/bragg-router)

> Router middleware for [bragg](https://github.com/SamVerschueren/bragg).


## Install

```
$ npm install --save bragg-router
```


## Usage

```js
const app = require('bragg')();
const router = require('bragg-router')();

router.get('/', ctx => {
    ctx.body = 'Home';
});

router.get('/user/{id}', ctx => {
    ctx.body = `Retrieve user with id ${ctx.request.params.id}`;
});

app.use(router.routes());

exports.handler = app.listen();
```

### Multiple handlers

When a handler returns a promise, that promise will be resolved first. The result of following example will be `Foo Bar`.

```js
const app = require('bragg')();
const router = require('bragg-router')();

router.get('/',
	() => Promise.resolve('Foo');
	(ctx, result) => {
		ctx.body = `${result} Bar`;
	}
);

app.use(router.routes());

exports.handler = app.listen();
```

## Mapping template

In order for you to use the router, you will have to add extra properties to your [mapping template](https://github.com/SamVerschueren/bragg#mapping-template).

```json
{
    "resource-path": "$context.resourcePath",
    "http-method": "$context.httpMethod"
}
```

[Bragg](https://github.com/SamVerschueren/bragg) will detect these properties and expose them as `path` and `method` properties in the middlewares.


## API
{'fraction_non_alphanumeric': 0.18673050615595074, 'fraction_numerical': 0.0, 'mean_word_length': 4.4672897196261685, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7262118', 'n_tokens_mistral': 992, 'n_tokens_neox': 967, 'n_words': 238}