
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
hapi-rest-methods
Advanced tools
Add REST HTTP methods directly to server object of hapi.JS framework to easily add routes
Add REST HTTP methods directly to server object of hapi.JS framework to easily add routes.
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).
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('...');
});
Use github issues.
MIT
FAQs
Add REST HTTP methods directly to server object of hapi.JS framework to easily add routes
The npm package hapi-rest-methods receives a total of 2 weekly downloads. As such, hapi-rest-methods popularity was classified as not popular.
We found that hapi-rest-methods demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.