# route-methods

> generate uniform list of routes and associated methods

Latest version **0.0.2** (published 2015-08-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install route-methods
pnpm add route-methods
yarn add route-methods
bun add route-methods
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2015-08-10 |
| First published | 2015-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jon Nyman |
| Maintainers | jon49 |
| Keywords | route, routing |

## Links

- npm: https://www.npmjs.com/package/route-methods
- Repository: https://github.com/jon49/route-methods
- Issues: https://github.com/jon49/route-methods/issues
- npm.io page: https://npm.io/package/route-methods

## Dependencies (1)

- [ramda](https://npm.io/package/ramda.md) ^0.17.1

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2015-08-10
- 0.0.1 — 2015-08-10
- 0.0.0 — 2015-08-07

## README

## Summary

`route-methods` creates a list of routes and their methods from a nested
structure. This makes it easier to create nested APIs.

`route-methods` was originally created to work with autoroute-base libraries
like `autoroute-express-promise`.

## Installation

Install with `npm`:

```
npm install --save route-methods
```

## Project Status

- Beta
- Active (August 10, 2015)

## Examples

```js
enum method { get, post }

const normalRoute = {
    route: '/yep/its/normal/:id',
    methods: [
        [ method.get,   'OK' ]
        [ method.post,  'Posted' ]]
}

flattenRoute(normalRoute) // => [normalRoute]

const simpleRoute = {
    '/dogs': [[
        method.get, 'many dogs' ]],
}

flattenRoute(simpleRoute)
// =>
// [{
//     route: '/dogs',
//     methods: [[method.get, 'many dogs']]
// }]

const complexRoute = {
    '/cats': {
        _methods: [[
            method.get,     'all cats' ]],
        mine: [[
            method.get,     'my cat',
            method.post,    'a new cat' ]],
        ':id': [[
            method.get,     'a special cat' ]]
}}

flattenRoute(complexRoute)
// =>
// [
//     {route: '/cats', methods: [[method.get, 'all cats']]},
//     {route: '/cats/mine', methods: [[ method.get, 'my cat', method.post, 'a new cat' ]]},
//     {route: '/cats/:id', methods: [[ method.get, 'a special cat' ]]}
// ]

const newNestedRoute = {
    '/hamsters': {
        '/fish': [[
            method.post,    'hamsters bite' ]]
    }
}

flattenRoute(newNestedRoute)
// =>
// [{
//    route: '/fish',
//    methods: [[ method.post, 'hamsters bite' ]]}])
// })
```

## API

```js
import {subRoutes, flattenAltRoute, flattenRoute} from 'route-methods'
```

where `RouteDefinition` is

```js
interface RouteDefinition<T, S> {
    /**
    * Route name, e.g., route: "/api/myroute/:id"
    */
    route: string
    /**
    * E.g., methods: [
    *   [method.get, req => myFunctionThatReturnsAPromiseGet(req.params["theIdName"])],
    *   [method.delete, req => myFunctionThatReturnsAPromiseDelete(req.params["theIdName"])]
    * ]
    */
    methods: [[T, S]]
}
```

**`subRoutes <T, S>(routes: [string, any]): RouteDefinition<T, S>[]`**

where `routes`

Tuple, [route, child routes and/or route methods]

**`flattenAltRoute <T, S>(nestedRoutes: any): RouteDefinition<T, S>[]`**

where `nestedRoutes` has the form seen the examples. Can be a mixture of the
different examples.

**`flattenRoute <T, S>(routeDefinition: any): RouteDefinition<T, S>[]`**

where `routeDefinition` can be the same argument in `flattenAltRoute` or the
`normalRoute` seen the examples.

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