
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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 12 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.