Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-methods

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-methods

server method helper

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-91.67%
Maintainers
4
Weekly downloads
 
Created
Source

#hapi-methods Build Status NPM version Dependencies

My narrow helper for server-methods, use it, or don't. Assumes that you are caching your method results.

Benefits:

  • does a request.log(["cachemiss"], ...) so you can track the hit/miss ratio
  • generates a sha1 key instead of stringifying the input args (useful if you have large input objects)
  • what more do you need?
var catbox-redis = require("catbox-redis");
var Hapi = require("hapi");
var server = new Hapi.Server({
  cache: {
        engine: require("catbox-redis"),
        host: 127.0.0.1
    }
});

server.connection({ port: 3000 });

var methods = require("hapi-methods");
var config = {
  expiryInSeconds: 60
};

var methods = {
  add: function(a, b, next){
    next(null, a+b);
  }
};

methods.register(server, config, methods);

server.route({
    method: 'GET',
    path: '/add/{one}/{two}'
    handler: function(req, res){
      req.server.methods.add(req.params.one, req.params.two, req, function(err, result){
        if(err){
          reply(err);
        }

        reply(result);
      });
    }
});

server.start(function(){
  console.log('server started...');
});

Keywords

FAQs

Package last updated on 19 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc