mio-resource

Expose Mio models via RESTful resource middleware.

mio-resource

Expose Mio models via RESTful resource middleware.

This module can be paired with mio-ajax for automatic client-server communication.

npm install mio-resource

Use with express:

var express = require('express')
  , mio = require('mio');
 
var User = mio.createModel('User');
 
User
  .attr('id')
  .attr('name')
  .use('server', 'mio-resource');
 
var app = express();
 
app
  .use(express.bodyParser())
  .get('/users', User.middleware.index)
  .post('/users', User.middleware.create)
  .get('/users/:id', User.middleware.show)
  .put('/users/:id', User.middleware.update)
  .del('/users/:id', User.middleware.destroy);

Use with express-resource:

app.resource('users', User.middleware);

Emitted whenever a model instance is loaded inside of a request.

User.on('request loaded model', function(requser) {
  // ... 
});