@dvpnt/express-api-resource
v1.0.0
Published
convenient wrapper for express router for easy REST API building and composing
Downloads
2
Readme
@dvpnt/express-api-resource
Convenient wrapper for express router for easy REST API building and composing.
Installation
$ npm install @dvpnt/express-api-resource
Usage
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);