Framework for create server rest API.
npm install --save methodjs
index.js
const methodjs = require('methodjs').getInstance();
methodjs.eco.db = require('./libs/somedb'); //add your db module to ecosystem
methodjs.loadTreeFromDir(__durname+'/methods/'); // load all modules from dir
methodjs.express(app); //register urls for methods in your express.js app
mkdir methods # create dir for method files
mkdir methods/time # create time object
touch methods/time/current.js # create file for time.current method
methods/time/current.js:
const methodjs = require('methodjs').getInstance();
const app = express();
methodjs.registerRead('time', {}, function current({req, res}) {
return new Promise(function (resolve, reject) {
resolve({ time: new Date().toLocaleTimeString() });
})
});
curl 127.0.0.1:3000/time/current