0.0.3 • Published 11 years ago
mr8 v0.0.3
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 ThingsGET http://hostname:port/mr8/Thing/1
- get Thing with_id
= 1POST http://hostname:port/mr8/Thing
- create ThingPUT http://hostname:port/mr8/Thing/1
- update Thing with_id
= 1DELETE 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
});