Socket
Socket
Sign inDemoInstall

sequelize-router

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sequelize-router

A restful route generator for Sequelize.


Version published
Weekly downloads
7
increased by133.33%
Maintainers
1
Install size
7.09 kB
Created
Weekly downloads
 

Readme

Source

Sequelize Router :sunglasses:

An easy to use, RESTful route generator designed to work with Sequelize.

NPM

Why use Sequelize Router?

  • It's tiny (2kb unminified)

  • It's easy to use! You can get up and running in about a minute with almost zero configuration.

  • It's customizable and extensible. Easily override any of the default route controllers.

Installation

Available on npm:

npm install sequelize-router

Prerequisites

  • sequelize-router is middleware that runs on top of sequelize, a popular ORM for node.js applications. Therefore, make sure that you have configured a database prior to use.

  • (Optional) Consider using sequelize-cli to quickly scaffold models of your database to be used for even quicker deployement:

$ npm install --save-dev sequelize-cli
$ npm install --save sequelize
$ sequelize init:config init:models

Usage

var express = require('express');
// Require the sequelize-router middleware and any models to be used
var sequelizeRouter = require('sequelize-router');
var db = require('./models');

var app = express();
// Use the sequelize-router middleware as shown below
app.use('/api', sequelizeRouter(db.Inventory)); 
app.use('/api', sequelizeRouter(db.Store));
app.use('/api', sequelizeRouter(db.Transaction));

That's literally it. :boom: Restful API Routes are now created for three models.

  • In the example above, RESTful API routes are being created for the Inventory, Store and Transaction models. Model names are lowercased and used to construct endpoints.

API Documentation

HTTP methodURLDescription
GET/api/inventoryRuns a findAll query on the inventory table, additionally filterable with optional query parameters.
*e.g. /api/inventory?stock%5Blte%5D=50 or /api/inventory?category=home_improvement
GET/api/inventory/:idRuns a findOne query on the inventory table and retrieves one record with the id specified in req.params.id.
POST/api/inventory/Runs a create query on the inventory table, using data passed in req.body to construct the new record.
PUT/api/inventory/:idRuns an update query on the inventory table, using data passed in req.body to update the record with the id specified in req.params.id. By default, query parameters are ignored.
DELETE/api/inventory/:idRuns an destroy query on the inventory table, using data passed in req.body to update the record with the id specified in req.params.id. By default, query parameters are ignored.

Defaults

  • By default, each endpoint responds with the data retrieved from the Sequelize query, or from the error returned.

  • Defaults are can be easily overridden for any model's methods by passing a configuration object into the sequelize-router middleware. Further documentation on this to come.

Authors

Christian Eckenrode

Contributors

Keywords

FAQs

Last updated on 13 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc