0.1.4 • Published 7 years ago

bearded-route-list v0.1.4

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

#Bearded Route List

I just want to know what the hell I'm doing

This attaches the express.Router() instance to given endpoints inside of routes along with building a list of all available endpoints along with the methods. See Example for use case and sample output

##Usage

yarn add bearded-route-list

##Import/Require

import baseList from 'bearded-route-list'

// OR

const baseList = require('bearded-route-list')

##Example

// Import the package
import baseList from 'bearded-route-list'

// Create routes/handlers
const UserRoute = express.Router(),
      AuthRoute = express.Router(),
      app = express()

// ...
// add endpoints to route
// ...

const routes = [
  {
    path: '/users',
    handler: UserRoute
  },
  {
    path: '/auth',
    handler: AuthRoute
  }
]

baseList(routes,app) // this will hook into the route '/'

// OR

baseList(routes, app, '/list') // this will hook into route '/list'

And going to '/' will return this:

{
  "/auth": {
    "/login": {
      "methods": {
        "post": true
      }
    }
  },
  "/users": {
    "/": {
      "methods": {
        "get": true,
        "post": true
      }
    },
    "/:_id": {
      "methods": {
        "delete": true,
        "get": true,
        "patch": true
      }
    }
  }
}

##Description

(routes = [], app, base = '/')

With routes being an array of objects with the following syntax:

{
  path: String,
  handler: express.Router()
}

App being an express() instance

base being the route you want the list of endpoints to be at.

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago