Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    mr8public

    Usage

    Code example

    var express = require('express');
    var mongoose = require('mongoose');
    var mr8 = require('mr8')(mongoose);
    var app = express();
     
    mongoose.connect('mongodb://localhost/test', function() {
        mr8.applyTo(app, {options...}); // See lib/options.js for options reference
        http.createServer(app).listen(8080);
    })

    Supported requests:

    • GET http://hostname:port/mr8/Thing - get Things
    • GET http://hostname:port/mr8/Thing/1 - get Thing with _id = 1
    • POST http://hostname:port/mr8/Thing - create Thing
    • PUT http://hostname:port/mr8/Thing/1 - update Thing with _id = 1
    • DELETE http://hostname:port/mr8/Thing/1 - delete Thing with _id = 1

    Supported query modifiers:

    See lib/queryBuilders for supported query modifiers such as where, limit, skip, etc.

    Events

    mr8 object contains ee property which is an EventEmitter instance. After each affecting request (POST, PUT, DELETE) it emits two events: %action%:post and %action%:post:%name, where %action% is action name ('create', 'update', 'delete' respectievely) and %name% is affected model name.

    Example

    // POST http://hostname:port/mr8/Thing
    mr8.ee.on('create:post', function(name, data) {
        // 'name' is a model name ('Thing' in our example)
        // 'data' is the created Thing instance
    });
     
    // PUT http://hostname:port/mr8/Thing/1
    mr8.ee.on('update:post:Thing', function(data) {
        // 'data' is the updated Thing instance
    });

    Keywords

    none

    install

    npm i mr8

    Downloadsweekly downloads

    8

    version

    0.0.3

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar