Skip to content

johnmanko/hapi-mongoose-handlers

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapi-mongoose-handlers

REST handlers for models created in mongoose

Install

$ npm install hapi-mongoose-handlers

Usage

var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 8000 });

server.register([{
        register: require('hapi-mongoose-connect'),
        options: {
            mongooseUri: 'mongodb://localhost/my-database'
        }
    }, {
        register: require('hapi-mongoose-models'),
        options: {
            globPattern: './models/**/*.js',
            globOptions: {
                cwd: __dirname
            }
        }
    }, {
        register: require('hapi-mongoose-request'), // REQUIRED
        options: {
            param: 'model',
            capitalize: true,
            singularize: true
        }
    }, {
        register: require('hapi-mongoose-handlers'),
        options: {
            find: function (route, options) {},     // Custom handler
            meta: {                                 // Can personalize the meta information
                totalPagesKey: 'count'
            },
            onCreate: 'object',                     // Determine what information will return
            onRemove: 'no-content',
            where: true                             // Can activate advanced searches (be careful with this)
        }   
    }], function (err) {

        if (err) {
            throw err;
        }

        server.route({
            method: 'GET',
            path: '/api/{model}/{id?}'              // hapi-mongoose-request Plugin is necessary
            handler: {
                find: {}
            }
        });

        // Now can visit `/{yourmodel}/{id?}

        server.start(function (err) {

            if (err) {
                throw err;
            }
            console.log('Server started at: ' + server.info.uri);
        });
    }
});

Tests

Run comand make test or npm test. Include 100% test coverage.

License

MIT

About

REST handlers for models created in mongoose

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.4%
  • Makefile 1.6%