koa-router-crud-repository
v1.0.0
Published
Function to generate koa-router with crud routes from repository.
Downloads
5
Maintainers
Readme
koa-router-crud-repository
Create koa-router with crud routes for a repository.
Requirements
- node ^7.6.0
Installation
npm install --save koa koa-router koa-router-crud-repository
Usage
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import compose from 'koa-compose';
import createRepositoryRouter from 'koa-router-crud-repository';
import provinceRepository from '...';
import cityRepository from '...';
// make sure to use after koa-error
const app = new Koa();
app.use(bodyParser());
const provinceRouter = createRepositoryRouter(provinceRepository, { prefix: '/provinces' });
const cityRouter = createRepositoryRouter(provinceRepository, { prefix: '/cities' });
const routes = compose([
provinceRouter.routes(),
provinceRouter.allowedMethods(),
cityRouter.routes(),
cityRouter.allowedMethods()
]);
app.use(routes);
License
MIT