https://github.com/srcagency/http-routing
Simple routing
https://github.com/srcagency/http-routing
http
Last synced: 2 months ago
JSON representation
Simple routing
- Host: GitHub
- URL: https://github.com/srcagency/http-routing
- Owner: srcagency
- Created: 2014-10-07T09:33:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-12-06T22:48:15.000Z (over 9 years ago)
- Last Synced: 2025-11-02T19:13:02.793Z (5 months ago)
- Topics: http
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# http routing
Simple, unobtrusive routing of HTTP requests (a url and a verb) for the server
or a browser.
Started as a research project in routing *without regular expressions*.
## example
```js
var router = require('http-routing');
// create a new index of routes
var routes = [
router.route('GET', '/ping', 'A'),
router.route('GET', '/echo/:word', 'B'),
];
router.match(routes, 'GET', '/anything'); // undefined
router.match(routes, 'POST', '/ping'); // undefined
router.match(routes, 'GET', '/ping');
/*
{
method: 'GET',
signature: '/ping',
params: [],
value: 'A',
args: [],
query: '',
}
*/
router.match(routes, 'GET', '/echo/bam?a=b');
/*
{
method: 'GET',
signature: '/echo/:',
params: [ 'word' ],
value: 'B',
args: [ 'bam' ],
query: 'a=b',
}
*/
```
## Install
```sh
npm install http-routing
```
## Test
```sh
npm test
```