rest interface generation for sequelize models

Usage no npm install needed!

<script type="module">
  import expressRestOrm from '';



travis coveralls npm-version npm-downloads npm-license twitter

express-rest-orm generates an express Router that serves a list of sequelize Models via a full-featured REST api.

getting started

Get the latest version of express-rest-orm via npm:

npm install [--save] express-rest-orm

Then use it to serve your sequelize Models:

var app = require('express')()
  , Sequelize = require('sequelize')
  , orm = new Sequelize('example', ...)
  , models = [orm.define('foo', ...), orm.define('bar', ...)];

app.use('/api/v1', require('express-rest-orm')(models));

running the tests

Tests are the main source of documentation for this module. They are kept readable so that they will not only pass but also convey information to the reader.

npm test

will run all tests and give a spec as well as coverage information.

See the latest travis build if you don't want to run the tests locally.

feature list

This is both a documentation of the features of express-rest-orm and a backlog of planned improvements. It is more or less copied from express-persistent-resource.

  • /: all resources
    • OPTIONS /: list methods
    • GET /: list resource urls
    • POST /: create resource
    • PUT /: bulk update resources
    • DELETE /: delete all resources
  • /:id: a single resource
    • GET /:id: read resource
    • POST /:id: error -> use PUT /:id or POST /
    • PUT /:id: update resource
    • DELETE /:id: delete resource
  • /:id/:field: all nested resources
    • GET /:id/:field: list nested resources (simulate with GET /:id?fields=:field)
  • ?: query parameters
    • ?include_docs=true: when GET /?include_docs, list docs instead of urls
    • ?:field=: list resources that match filter on field. Support
      • =: exact match
      • ~=: one of
      • |=: exact match or starts with + - (namespacing)
      • ^=: starts with
      • $=: ends with
      • *=: contains
    • ?fields=: partial response (filtered by untyped.validate)
    • ?limit= and ?offset=: pagination (limit entries per call, offset entries skipped)
    • ?q=: search resources for query
    • ?method=: override http method with method (GET /?method=POST equals POST /)
    • ?suppress_response_codes=true: override response code with 200, put response code in result
  • .:ext: resource serialization
    • .json: (default) resources as json
    • .xml: resources as xml
    • .yml: resources as yaml
  • Accept:: resource serialization
    • */json: resources as json
    • */xml: resources as xml
    • */yml: resources as yaml