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);
})
-
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
See lib/queryBuilders
for supported query modifiers such as where
, limit
, skip
, etc.
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.
// 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
});