# restizr

> A simple REST mapper for Sequelize

Latest version **0.5.2** (published 2012-07-30) · 0 weekly downloads

## Install

```sh
npm install restizr
pnpm add restizr
yarn add restizr
bun add restizr
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2012-07-30 |
| First published | 2012-04-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Guido Bellomo |
| Maintainers | Guido Bellomo |

## Links

- npm: https://www.npmjs.com/package/restizr
- Repository: http://github.com/guidone/Restizr
- npm.io page: https://npm.io/package/restizr

## Dependencies (2)

- [sugar](https://npm.io/package/sugar.md) 1.2.5
- [sequelize](https://npm.io/package/sequelize.md) >= 1.3.5

## Recent versions

- 0.5.2 (latest) — 2012-07-30
- 0.5.1 — 2012-07-03
- 0.5.0 — 2012-04-15

## README

# 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/<id>: get the record with primary key <id> 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/<id>: delete the record with primary key <id> from the table "user"
- PUT /api/user/<id>: update the record with primary key <id> 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.

---
_Source: https://npm.io/package/restizr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
