osprey-router

1.0.0 • Public • Published

Osprey Router

NPM version Build status Test coverage Greenkeeper badge

Simple middleware-style router for RAML based on router.

Installation

npm install osprey-router --save

Usage

This module is an instance of router with support for RAML paths and parameters.

Router(options)

All options and functions from router are supported, except the second argument can be an optional array of webapi-parser Parameter objects. For example:

const finalhandler = require('finalhandler')
const http = require('http')
const Router = require('osprey-router')
const utils = require('./utils')
 
const router = Router()
const parameters = utils.getUriParameters()
 
router.get('/{userId}', parameters, function (req, res) {
  console.log(typeof req.params.userId)
 
  res.setHeader('Content-Type', 'text/plain; charset=utf-8')
  res.end(req.params.userId)
})
 
const server = http.createServer(function (req, res) {
  router(req, res, finalhandler(req, res))
})
 
server.listen(3000)

When you specify the parameter type, it'll automatically be parsed in the native JavaScript type.

License

Apache 2.0

/osprey-router/

    Package Sidebar

    Install

    npm i osprey-router

    Weekly Downloads

    1,053

    Version

    1.0.0

    License

    Apache-2.0

    Unpacked Size

    7.51 kB

    Total Files

    4

    Last publish

    Collaborators

    • cesaraugustogarcia
    • jstoiko
    • mulesoft-npm