Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple REST mapper for Sequelize

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore link + ignore
Octocat-spinner-32 README.md fix array on single record, added extend
Octocat-spinner-32 index.js Merge branch 'master' of github.com:guidone/Restizr
Octocat-spinner-32 package.json Merge branch 'master' of github.com:guidone/Restizr
README.md

Restizr

Restizr is a lightweight REST layer for NodeJS+ExpressJS+Sequelize: given a Sequelize model, automatically creates the REST end points (GET,PUT,POST,DELETE) at specific URL.

Example

For example, given the model var User = sequelize.define('User', { id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true }, username: { type: Sequelize.STRING }, password: { type: Sequelize.STRING } });

These simple commands: var Restizr = require('restizr'); var rest = new Restizr(app); // ExpressJS app rest.map(User);

will create the following REST endpoints:

  • GET /api/user: list first 10 records of the table "user". Accepts parameters: - limit: the number of records to retrieve - offset: zero based index of the starting record - sort: field used for sorting - direction: could be 'asc' or 'desc' - filter: field used for filtering
    • query: query used to filter Example: /api/user?limit=20&offset=10 To override this values, just insert a onBefore middleware and add or modify keys to the object request.queryString
  • GET /api/user/: get the record with primary key from the table "user"
  • POST /api/user: create a new entry in the table "user", returns the primary key of the new record
  • DELETE /api/user/: delete the record with primary key from the table "user"
  • PUT /api/user/: update the record with primary key from the table "user"

Where id is the primary key in the MySQL table.

Options

  • basepath(default: '/api'): change here to attach the resource REST API to a specific end point
  • engine(default: 'sequelize'): the engine used for the storage, currently only Sequelize in supported
  • limit(default: 10): number of records returned while listing
  • onBefore,onAfter: middlewares executed at the before each request, this is a good place to check session for securing the calls to APIs
  • onBeforeAll,onAfterAll: middlewares execute before and after the listing of the records
  • onBeforeGet,onAfterGet:
  • onBeforePost,onAfterPost:
  • onBeforePut,onAfterPut
  • onBeforeDelete,onAfterDelete:

Using middlewares

Restizr accepts a number of middlewares to be executed before or after the sigle REST operation in order to perform basic operation, for example check credentials of the client or format the output.

....

Examples on the real world

TBD

Known issues

Currently the module it's in an alpha stage. Error handling is not well supported.

Something went wrong with that request. Please try again.