Registry / devops / rest-router-model

rest-router-model

JSON →
library1.9.5jsnpmunverified

rest-router-model v1.9.5 is a Koa-based REST API generator that automatically creates RESTful HTTP endpoints from a JSON resource configuration, while also handling data model mapping to SQL databases via Knex. It supports PostgreSQL, MSSQL, MySQL, MariaDB, SQLite3, Oracle, and Amazon Redshift. Its key differentiator is the ability to define resource hierarchies (super) and many-to-many relationships (membership) declaratively, reducing boilerplate. The library is in maintenance mode, with last release in 2018, and requires Node >=8.9.0 and Koa. It does not support TypeScript, browser, or GraphQL.

npm install rest-router-model
INSTALL
IMPORT
SIG · REST-ROUTER-MODEL
R
rest-router-model
devopsjavascriptv1.9.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

restRouterModel
const restRouterModel = require('rest-router-model')
import restRouterModel from 'rest-router-model'
Library is CommonJS only; ESM import not supported.
default
const restRouterModel = require('rest-router-model');
const { koaRestRouter } = require('rest-router-model')
Main export is a function; named export does not exist.
koaRestRouter
restRouterModel.koaRestRouter(resourceConfig, extendBusinesses, knexConfig, options)
restRouterModel(app, config)
Returns a Promise that resolves to a Koa router; must be awaited.

Creates a Koa app with automatic REST endpoints from a resource config using rest-router-model.

const Koa = require('koa'); const restRouterModel = require('rest-router-model'); const resourceConfig = { class: { rest_api: 'base', params: { name: { type: 'string' }, description: { type: 'string' }, createdAt: { type: 'time' }, modifiedAt: { type: 'time' }, }, }, }; const app = new Koa(); const knexConfig = { client: 'sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true, }; const options = { serverName: 'TestServer', ip: 'localhost', port: '3000', }; restRouterModel.koaRestRouter(resourceConfig, {}, knexConfig, options) .then(router => { app.use(router.routes()); app.listen(3000); console.log('Server running on port 3000'); }) .catch(err => { console.error('Failed to start server:', err); });
Debug
Known issues
deprecatedrequire('rest-router-model') returns default export; no named exports
fix
Use const restRouterModel = require('rest-router-model'); then call methods on it.
affects: >=1.0.0
breakingknexConfig must be an object with client and connection; missing required fields causes silent failures
fix
Ensure knexConfig includes client (e.g., 'sqlite3') and connection object.
affects: >=1.0.0
gotchaResource names in config are automatically pluralized for routes (e.g., 'class' becomes '/api/:version/classes')
fix
Use singular resource name in config; do not manually pluralize.
affects: >=1.0.0
gotchaDatabase tables are auto-created with a required 'uuid' primary key column; custom primary keys are not supported
fix
Design resource model with a 'uuid' field or accept auto-generated UUIDs.
affects: >=1.0.0
gotchaOptions object requires serverName, ip, and port to be strings; missing fields cause runtime errors
fix
Provide all three options: serverName, ip, port.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'routes' of undefined
koaRestRouter promise rejected or not awaited
fix
Ensure .then() is used or await the result.
Error: knex: Required configuration option 'client' is missing
knexConfig.client omitted or misspelled
fix
Set knexConfig.client correctly, e.g., 'mysql'.
Error: listen EADDRINUSE :::3000
Port already in use
fix
Change port in options or kill existing process.
Upgrade
Version history
1.9.5latest on npm
Audit
Dependencies
koarequiredCore peer dependency; requires Koa.js framework to mount routes
knexrequiredSQL query builder required for database interactions
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
rest-router-model — npm install rest-router-model · libregistry