Package Exports
- micro-route
- micro-route/dispatch
- micro-route/match
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micro-route) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
micro-route
🎛 Tiny http routing helper based on
url-pattern
Installation
Install from NPM:
$ npm install micro-route --save
Examples
const route = require('micro-route')
const corsRoute = route('*', 'OPTIONS')
const fooRoute = route('/', ['POST', 'PUT'])
const barRoute = route('/api/collection/:id', 'DELETE')
const anotherRoute = route('/api/transactions/:id')
module.exports = function (req, res) {
if (corsRoute(req)) {
// Send CORS headers
} else if (fooRoute(req)) {
// Do cool stuff
}
}
const match = require('micro-route/match')
module.exports = function (req, res) {
const { params, query } = match(req, '/api/transactions/:id?ts=12', true)
console.log('Transaction id:', params.id)
console.log('ts:', query.ts)
}
const dispatch = require('micro-route/dispatch')
module.exports = dispatch()
.dispatch('*', 'OPTIONS', (req, res) => ... )
.dispatch('/', ['POST', 'PUT'], (req, res) => ... )
.dispatch('/api/collection/:id', 'DELETE', (req, res) => ... )
.dispatch('/api/transactions/:id', '*', (req, res, { params, query }) => ... )
.otherwise((req, res) => ... )