0.0.3 • Published 11 years ago

mr8 v0.0.3

Weekly downloads
1
License
-
Repository
github
Last release
11 years ago

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
});
0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago