This package has been deprecated

Author message:

This module has moved and is now available at @hapi/call. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.

call

5.0.3 • Public • Published

call - Simple HTTP Router

Build Status

Lead Maintainer - Eran Hammer

Introduction

call is a simple node.js HTTP Router. It is used by popular hapi.js 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.

Example

const Call = require('call');
 
// Create new router
const router = new Call.Router();
 
// Add route
router.add({ method: 'get', path: '/' }, { label: 'root-path' });
 
// Add another route
router.add({ method: 'post', path: '/users' }, 'route specific data');
 
// Add another route with dynamic path
router.add({ method: 'put', path: '/users/{userId}' }, () => { /* ...handler... */ });
 
// Match route
router.route('post', '/users');
/* If matching route is found, it returns an object containing
    {
        params: {},                     // All dynamic path parameters as key/value
        paramsArray: [],                // All dynamic path parameter values in order
        route: 'route specific data';   // routeData
    }
*/
 
 
// Match route
router.route('put', '/users/1234');
/* returns
    {
        params: { userId: '1234' },
        paramsArray: [ '1234' ],
        route: [Function]
    }
*/

API

See the detailed API Reference.

Readme

Keywords

Package Sidebar

Install

npm i call

Weekly Downloads

61,420

Version

5.0.3

License

BSD-3-Clause

Unpacked Size

23.1 kB

Total Files

7

Last publish

Collaborators

  • devinivy
  • marsup
  • nargonath
  • nlf