
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-quick-api-mongoose
Advanced tools
Quick Hapijs REST APIs with mixed Mongoose Schema and Joi
This package will simply convert passed schema configs to APIs in HapiJS with the help of get-it-ready.
The Schema Config should look like this:
//Person.js
var Mongoose = require('mongoose'),
Schema = Mongoose.Schema;
var Joi = require('joi');
let schema = {
firstName: { type: String, required: true, joi: Joi.string() },
lastName: { type: String, required: true, joi: Joi.string() },
photo: { type: String, required: false, joi: Joi.string() },
createdOn: { type: Date, required: false, default: Date.now, joi: Joi.date() }
}
export default {
definition: schema,
name: 'Person',
version: '0.1.0'
}
And in the HapiJS server can be simply coded in following way:
//index.js
//THIS FILE WILL BE BABEL TRANSPILED
import Hapi from 'hapi';
import Inert from 'inert';
import Vision from 'vision';
import Mongoose from 'mongoose';
const HapiSwagger = require('hapi-swagger');
import person from './Person';
const hapiQuickApiMongoose = require('hapi-quick-api-mongoose');
var config = {
server: {
host: '0.0.0.0',
port: process.env.PORT || 8000
}
};
// Create a server with a host and port
const server = new Hapi.Server();
server.connection(config.server);
//Connect and create placeholders
server.app.models = {};
server.app.db = Mongoose.createConnection(uri);
server.app.db.on('error', console.error.bind(console, 'connection error'));
server.app.db.once('open', function callback() {
console.log("Connection with database succeeded.");
});
//Register the plugins/modules
server.register([
Inert,
Vision,
{
'register': HapiSwagger,
'options': {
info: {
title: 'API Documentation',
version: 0.1.0,
}
}
},
{
register: hapiQuickApiMongoose,
options: {
connection: server.app.db,
models: [person]
}
}], err => {
console.log(err)
}
);
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
Now head over to browser on url http://localhost:8000/documentation and see the magic.
FAQs
Quick Hapijs REST APIs with mixed Mongoose Schema and Joi
The npm package hapi-quick-api-mongoose receives a total of 2 weekly downloads. As such, hapi-quick-api-mongoose popularity was classified as not popular.
We found that hapi-quick-api-mongoose 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.