Convenient wrapper for express router for easy REST API building and composing.
$ npm install @dvpnt/express-api-resource
const express = require('express');
const ApiResource = require('@dvpnt/express-api-resource');
const resource = new ApiResource({
root: 'entities',
versions: ['1.0'],
idAttributeName: 'id'
});
resource.getOne('1.0', (req, res) => {
res.json({id: 1, name: 'foo'});
});
resource.get('1.0', (req, res) => {
res.json([
{id: 1, name: 'foo'},
{id: 2, name: 'foo'}
]);
});
const app = express();
app.use('/api', resource);