mio-resource

Expose Mio models via RESTful resource middleware.

npm install mio-resource
3 downloads in the last day
19 downloads in the last week
31 downloads in the last month

mio-resource

Build Status Coverage Status NPM version Dependency Status

Expose Mio models via RESTful resource middleware.

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

Installation

npm install mio-resource

Example

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

Events

request loaded model

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

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

MIT Licensed

npm loves you