Sequelize Handlers
Create REST handers for Sequelize models
Installation
npm install sequelize-rest-handlers
Usage
Creating Individual Controllers
If you only need a couple of handlers you can create one for each model on your own with the syntax below. If you want to create an API for a series of models check out Creating Entire APIs.
const createController = ; const models = ; const app = ; const router = ; // The resulting router will be able to handle: // GET /api/v1/articles/ // GET /api/v1/articles/:articleId // PUT /api/v1/articles/:articleId // POST /api/v1/articles/ // DELETE /api/v1/articles/:articleId app; app;
Creating Entire APIs
If you just want to generate endpoints for all of your models you can use createRouter
.
const createRouter = ; const models = ; const app = ; const router = ; app; // The resulting app will be able to handle: // GET /api/v1/articles/ // GET /api/v1/articles/:articleId // PUT /api/v1/articles/:articleId // POST /api/v1/articles/ // DELETE /api/v1/articles/:articleId // GET /api/v1/posts // GET /api/v1/posts/:postId // PUT /api/v1/posts/:postId // ... etc ... app;
Query Parameters
Routes generated will support filtering in the Ember style i.e. `/api/v1/articles/?filter[published]=true.
In addition both limit
and offset
are supported.
Supported Hooks
beforeUpdate
afterUpdate
afterCreate