Socket
Socket
Sign inDemoInstall

hapi-rest-methods

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-rest-methods

Add REST HTTP methods directly to server object of hapi.JS framework to easily add routes


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

hapi-rest-methods

Add REST HTTP methods directly to server object of hapi.JS framework to easily add routes.

Build Status

Usage

Coming from ExpressJS and trying not to look back into it, I was introduced to HapiJS, which is a nice alternative, but routes definition is an overkill, I like simplicity of ExpressJS, so I hooked some handy methods to the hapi server object.

Instead of doing:

server.route({
  type: 'GET',
  path: '/foo',
  handler: function(request, reply) {
    reply('bar');
  });
});

You can just do:

server.get('/foo', function(request, reply) {
  reply('bar');
});

Simple.

It also supports .post(), .put(), .patch(), .delete() and .options(). Use .any() to match all of the (alias for * method).

Usage

Simple usage:

  // new hapi server
  var hapi = require('hapi');
  var restMethods = require('../')
  var server = new hapi.Server();
  server.connection({ port: 8080 });
  // add hapi-rest-methods plugin
  server.register(restMethods);
  // keep. it. simple. stupid. :-)
  server.get('/fruit', function(request, reply) {
    reply('orange');
  });
  server.post('/grumpy', function(request, reply) {
    console.log(request.payload.name)
    reply('cat');
  });

Plays well with other plugins, such as hapi inert:

  var inert = require('inert');
  ...
  server.register(restMethods);
  server.register(inert);
  server.get('/', { file: 'public/index.html' });

And if you need to config routes, just pass 3 parameters (path, config, handler):

  var routeConfig = config: {
    description: 'Say hello!',
    notes: 'The user parameter defaults to \'stranger\' if unspecified',
    tags: ['api', 'greeting'],
    auth: { ... },
    cache: { ... }
    // ...
  }

  server.delete('/the-internet', routeConfig, function(request, reply) {
    reply('...');
  });

Issues & Contributing

Use github issues.

License

MIT

Keywords

FAQs

Package last updated on 13 Apr 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