Express JSON:API Controller
Base controller class for express apps to create JSON:API endpoints for sequelize models
Installation
yarn add @coding-blocks/express-jsonapi-controller
Usage
const DB = require('./models')
const UserSerializer = require('./serializers/user')
const { Controller } = require('express-jsonapi-controller')
const MyController = new Controller(
DB.User,
DB,
UserSerializer
)
router.get('/', MyController.handleQuery)
Creating Serializers
We use jsonapi-serializer for serializing models
module.exports = (included, type, config) => {
return {
attributes: ['firstName', 'lastName'],
...config
};
};
Available Methods
Controller.handleQuery()
Controller.handleCreate()
Controller.handleQueryById()
Controller.handleUpdateById()
Controller.handleDeleteById()