route

The main function used to create a route branch

Arguments

Name

Type

Description

routePath

Array

The array of paths for this branch

methods

Array

An array of Methods to listen for

middleware

Array

An array of middleware that should be applied to this route

If you set middleware at this stage, it will be applied regardless of method

Usage

const { router, response, methods } = require('octoris')
const middlewareFn = require('someMiddleware')

function handler (ctx) {
  return response.json(200, ctx.params)
}

router.route(['/', router.param('id')], [methods.GET(handler)])

// Or if you have middleware:
router.route(['/', router.param('id')], [methods.GET(handler)], [middlewareFn])

Last updated