amuse (ah mooz)
a super simple super opinionated nodejs microservice-friendly restful api.
amuse supports node 8.x with the harmony flag
node --harmony index.js
npm install
npm install --save amuse
examples
simple
const amuse = ; const conn = ;const app = ; app; app; app;
detailed with commentary
const amuse = ; // these are koa middlewaresconst loggerMiddleware = ;const roomMiddleware = ; /* const conn = { client: 'mysql', connection: { host: 'host', user: 'user', password: 'password', database: 'database', charset: 'charset', }, };*/const conn = ; const app = ; app; // this is a bookshelf modelapp; // this middleware runs on all requestsappmiddlewares; /* all middleware and validator additions return an unsubscribe function. if at any time you want to opt out, just call the unsub function */const unsub = appmiddleware;; // these validators happen when creating/updating a modelappresourcesrooms;appresourcesrooms;appresourcesrooms;appresourcesrooms; // this middleware runs on only requests to room resourcesappresourcesroomsmiddlewares; /* all of these are automatically created GET localhost:3000/rooms/ [{ id: 1, description: '...', title: '...'}, { id: 2, description: '...', title: '...'}] GET localhost:3000/rooms/1 { id: 1, description: '...', title: '...'} POST localhost:3000/rooms/ { description: '...', title: '...' } { id: 3, description: '...', title: '...' } PUT localhost:3000/rooms/3 { id: 3, description: '---', title: '---' } { id: 3, description: '---', title: '---' } DELETE localhost:3000/rooms/3 {}*/app; /* the standard amuse response object is as follows{ "success": true, "errors": null, "data": [ { "id": 2, "owner_id": 5, "description": "hello!", "created": "2017-07-25T07:00:00.000Z" }, { "id": 3, "owner_id": 5, "description": "hello!!!", "created": "2017-07-25T07:00:00.000Z" }, { "id": 4, "owner_id": 5, "description": "hello!!!!!!", "created": "2017-07-25T07:00:00.000Z" } ]}*/ /* amuse also handles errors in a similar way{ "success": false, "errors": [ { "owner_id": [ "Object did not pass validation for property owner_id" ], "description": [ "Descriptions must be at least five characters long" ] } ], "data": null}*/
notes
you might have to add your own flavor of database connection - postgres, maria, sqlserver. just npm install it.
please don't use this in production yet. thanks a bunch