# match-routes

> simple server-side router based on http-hash

Latest version **2.0.0** (published 2015-06-30) · 0 weekly downloads

## Install

```sh
npm install match-routes
pnpm add match-routes
yarn add match-routes
bun add match-routes
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2015-06-30 |
| First published | 2015-03-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | sethvincent |

## Links

- npm: https://www.npmjs.com/package/match-routes
- Repository: https://github.com/sethvincent/match-routes
- Issues: https://github.com/sethvincent/match-routes/issues
- npm.io page: https://npm.io/package/match-routes

## Dependencies (2)

- [extend](https://npm.io/package/extend.md) ^2.0.0
- [http-hash](https://npm.io/package/http-hash.md) ^1.1.0

## Recent versions

- 2.0.0 (latest) — 2015-06-30
- 1.1.1 — 2015-03-29
- 1.1.0 — 2015-03-27
- 1.0.1 — 2015-03-02
- 1.0.0 — 2015-03-02

## README

# match-routes

a simple server-side router based on [http-hash](https://github.com/Matt-Esch/http-hash).

## api


### router.on(path, callback)

`callback` is called with three arguments, `req`, `res`, and `options`

The `options` object includes `params`, `splat`, and all the properties returned by `url.parse()` and will look something like this:

```
{ protocol: null,
  slashes: null,
  auth: null,
  host: null,
  port: null,
  hostname: null,
  hash: null,
  search: null,
  query: null,
  pathname: '/oh/awesome',
  path: '/oh/awesome',
  href: '/oh/awesome',
  parse: [Function],
  format: [Function],
  resolve: [Function],
  resolveObject: [Function],
  parseHost: [Function],
  params: { id: 'awesome' },
  splat: null 
}
```

Example:

```
router.on('/', function (req, res, options) {
  console.log(options)
})
```

### router.set(path, callback)

Alias to `router.on()`.

### router.match(req, res, opts)

```
http.createServer(function (req, res) {
  router.match(req, res)
})
```

## example usage

```
var http = require('http')
var response = require('response')
var router = require('./index')()

router.on('/', function (req, res, options) {
  response().html('this route exists').pipe(res)
})

var server = http.createServer(function (req, res) {
  if (router.match(req, res)) return
  
  response().html('this route does not exist').pipe(res)
})

server.listen(8989)
```

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