Skip to content

Iridium Model REST Mapper for Express and Seneca

License

Notifications You must be signed in to change notification settings

gothammm/otomatk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Otomatk

A tiny REST-like mapper for Iridium models with Seneca micro-services toolkit and express.js

Status

Build Status

TODO

  • More test cases

Install

npm install --save otomatk

Using with Express.js

const Otomatk = require('otomatk');
const Expressify = Otomatk.Expressify;
const app = require('express')();

// Generate REST Middlewares for Iridium Model.
const item = new Expressify(ItemModel);

// Usage.
app.get('/', item.get());
app.post('/', item.save());
app.put('/:id', item.save());
app.delete('/:id', item.remove());
app.get('/:id', item.detail());

Using with seneca.

const Otomatk = require('otomatk');
const Senecafy = Otomatk.Senecafy;
const seneca = require('seneca')();

// You can provide your own seneca role name.
var senecafy = new Senecafy(seneca, rolename);

senecafy.load([IridiumModel]) 

// You can also send as a single iridium model
senecafy.load(IridiumModel);


// Using the senecafied action patterns of the model.
seneca.act({ role: rolename, plugin: IridiumModel.collectionName, cmd: 'list' }, (err, data) => {
  // Other logic.  
}); 

Available Commands

// Similar to seneca data entities.
{ cmd: 'save' } // usage - { cmd: 'save', data: <data object to be saved> }
{ cmd: 'list' } // usage - { cmd: 'list', options: { sort: <mongo field sort indexspecification>, limit: <limit value>, skip: <skip value> }, fields: <field selection> } 
{ cmd: 'remove' } // usage - { cmd: 'remove', id: <object id of record to be removed> }
{ cmd: 'load' } // load - { cmd: 'load', id: <object id to be loaded> }

NOTE: The plugin name for all the senecafied patterns are mostly the name of the Iridium Collection/Model (Model.collectionName)

About

Iridium Model REST Mapper for Express and Seneca

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published