UNPKG

1.53 kBMarkdownView Raw
1# call - Simple HTTP Router
2
3[![Build Status](https://secure.travis-ci.org/hapijs/call.png)](http://travis-ci.org/hapijs/call)
4
5### Lead Maintainer - [Eran Hammer](https://github.com/hueniverse)
6
7## Introduction
8`call` is a simple node.js HTTP Router. It is used by popular [hapi.js](https://github.com/hapijs/hapi) web framework. It implements predictable and easy to use routing. Even if it is designed to work with Hapi.js, you can still use it as an independent router in your app.
9
10## Example
11
12``` javascript
13const Call = require('call');
14
15// Create new router
16const router = new Call.Router();
17
18// Add route
19router.add({ method: 'get', path: '/' }, { label: 'root-path' });
20
21// Add another route
22router.add({ method: 'post', path: '/users' }, 'route specific data');
23
24// Add another route with dynamic path
25router.add({ method: 'put', path: '/users/{userId}' }, () => { /* ...handler... */ });
26
27// Match route
28router.route('post', '/users');
29/* If matching route is found, it returns an object containing
30 {
31 params: {}, // All dynamic path parameters as key/value
32 paramsArray: [], // All dynamic path parameter values in order
33 route: 'route specific data'; // routeData
34 }
35*/
36
37
38// Match route
39router.route('put', '/users/1234');
40/* returns
41 {
42 params: { userId: '1234' },
43 paramsArray: [ '1234' ],
44 route: [Function]
45 }
46*/
47```
48
49## API
50See the detailed [API Reference](./API.md).
\No newline at end of file