# jambon-router

> ``` $ npm install jambon-router ```

Latest version **1.0.1** (published 2018-01-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install jambon-router
pnpm add jambon-router
yarn add jambon-router
bun add jambon-router
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-01-10 |
| First published | 2018-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Jonatan Pedersen |
| Maintainers | jonatanpedersen |

## Links

- npm: https://www.npmjs.com/package/jambon-router
- npm.io page: https://npm.io/package/jambon-router

## Dependencies (2)

- [jambon](https://npm.io/package/jambon.md) ^1.0.1
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^2.1.0

## Recent versions

- 1.0.1 (latest) — 2018-01-10
- 1.0.0 — 2018-01-10

## README

# jambon-router

```
$ npm install jambon-router
```

## API
### path

``` javascript
function path(path: string, ...reducers: (async state => state)[]) : async state => state
```

Import `path` function:
``` javascript
import {path} from 'jambon-router'
```


Match requests where path starts with `/api`:
``` javascript
const reducer = path('/api', ...reducers});
```

Match requests where path is exactly `/api/foos`:

``` javascript
const reducer = path('/api/foos$', async (state) => {
	const foos = await getFoos();

	return {
		...state,
		response: {
			...state.response,
			body: foos,
			statusCode: 200
		}
	};
});
```

Using params:

``` javascript
const reducer = path('/api/foos/:fooId$',  async (state) => {
	const {fooId} = state.request.params;
	const foo = await findFoo(fooId);

	return {
		...state,
		response: {
			...state.response,
			body: foo,
			statusCode: foo ? 200 : 404
		}
	};
});
```


## method(method: string, ...reducers : AsyncReducerFunction[]) : AsyncReducerFunction

``` javascript
import {method} from 'jambon-router';

const methodReducer = method('POST', );



```

---
_Source: https://npm.io/package/jambon-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
