# literate-router

> Markdown powered routing

Latest version **1.5.0** (published 2017-10-24) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.5.0 |
| Published | 2017-10-24 |
| First published | 2016-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Maintainers | hij1nx |

## Links

- npm: https://www.npmjs.com/package/literate-router
- Repository: https://github.com/0x00A/literate-router
- Homepage: https://github.com/0x00A/literate-router#readme
- Issues: https://github.com/0x00A/literate-router/issues
- npm.io page: https://npm.io/package/literate-router

## Dependencies (3)

- [stream-body](https://npm.io/package/stream-body.md) ^1.0.2
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^1.7.0
- [stream-response](https://npm.io/package/stream-response.md) ^1.0.0

## Recent versions

- 1.5.0 (latest) — 2017-10-24
- 1.4.1 — 2017-04-18
- 1.4.0 — 2017-04-18
- 1.3.4 — 2017-02-26
- 1.3.3 — 2017-02-10
- 1.3.2 — 2017-01-11
- 1.3.1 — 2017-01-05
- 1.3.0 — 2016-12-23
- 1.2.0 — 2016-12-22
- 1.1.0 — 2016-12-22
- 1.0.0 — 2016-11-28

## README

# SYNOPSIS
Markdown powered routing for building http based APIs. A generalized routing
system meant to be both abstracted and self-documenting.

# MOTIVATION
Don't allow routing to become tangled with implementations. Enforce
markdown based documentation so it can be served as an endpoint. A single
canonical reference can also be used to test routes reliably.

# SYNTAX
Lines that are indented using two or more spaces or one or more tabs) are
parsed. All other lines are ignored (considered to be documentation). Arguments
(arbitrary string values separated by commas) are optional.

```
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

  METHOD ROUTE PATH (P1, P2, ...)

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

  METHOD ROUTE PATH (P1, P2, ...)
  METHOD ROUTE PATH (P1, P2, ...)
```

### METHOD
A regular expression, matching the http method, for example `GET|PUT`.

### ROUTE
A tokenized route, for example `/books/:page`, see
[this](https://github.com/pillarjs/path-to-regexp#parameters) documentation.

### PATH
A path to a file that exports one or more functions to handle testing and
fullfilling the request.

### (P1, P2, ...)
An array of arbitrary parameters that can be passed to the supplied functions.

# USAGE
## ROUTES.MD
```md
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

  GET /books routes/books (5000/hr)
  PUT|POST /books/:book routes/books (10000/hr)
```

## SERVER.JS
```js
const http = require('http')
const Router = require('literate-router')
const send = require('send')
const fs = require('fs')

function nonmatch (req, res) {
  send(req, req.url).pipe(res)
}

function match (req, res, context, next) {
  next()
}

const routes = fs.readFileSync('./routes.md', 'utf8')
const router = Router(routes, match, nonmatch)

http.createServer(router).listen(8080)
```

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