osprey-router
Simple middleware-style router for RAML based on router
Last updated 4 months ago by jstoiko .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install osprey-router 
SYNC missed versions from official npm registry.

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 uriParameters schema. For example:

var finalhandler = require('finalhandler')
var http = require('http')
var Router = require('osprey-router')

var router = Router()

router.get('/{userId}', {
  userId: {
    type: 'integer'
  }
}, function (req, res) {
  console.log(typeof req.params.userId) //=> "number"

  res.setHeader('Content-Type', 'text/plain; charset=utf-8')
  res.end(req.params.userId)
})

var 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

Current Tags

  • 0.6.3                                ...           latest (4 months ago)

18 Versions

  • 0.6.3                                ...           4 months ago
  • 0.6.2                                ...           6 months ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           2 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.0                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.2                                ...           4 years ago
  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.5                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 21
Dependencies (5)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |