Restifizer

0.8.36 · abandoned · verified Wed Apr 22

Restifizer is a JavaScript library designed to significantly simplify the creation of full-functional RESTful services, primarily for Node.js environments. As of version 0.8.36, it remains in a pre-1.0 state with its last known update around 2017, suggesting it is no longer actively maintained. It operates as a database-agnostic solution by leveraging plug-in data sources, specifically `restifizer-mongoose-ds` for MongoDB and `restifizer-sequelize-ds` for various SQL databases (MSSQL, MySQL, MariaDB, PostgreSQL, SQLite). Its key differentiator is its tight coupling with Mongoose and Sequelize ORMs, which allows it to expose rich ORM features—such as complex querying engines, nested object support, and data population—directly through HTTP requests. While this approach enables extremely rapid service development, developers must actively manage potential performance impacts in production, as default configurations may expose unindexed fields for filtering.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates setting up an Express application with Restifizer and Mongoose. It defines a 'User' resource, connects to a MongoDB database, and shows how to use Restifizer to expose basic CRUD operations via HTTP, including an example of restricted filtering.

const express = require('express');
const mongoose = require('mongoose');
const restifizer = require('restifizer');
const RestifizerMongooseDataSource = require('restifizer-mongoose-ds');

const app = express();
const PORT = process.env.PORT || 3000;

// 1. Connect to MongoDB
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost:27017/restifizer_example')
  .then(() => console.log('MongoDB connected'))
  .catch(err => console.error('MongoDB connection error:', err));

// 2. Define a Mongoose Schema and Model
const UserSchema = new mongoose.Schema({
  username: { type: String, required: true, unique: true },
  email: { type: String, required: true, unique: true },
  createdAt: { type: Date, default: Date.now }
});
const User = mongoose.model('User', UserSchema);

// 3. Configure Restifizer resources
app.use(express.json()); // For parsing application/json
app.use(restifizer.resources([
  {
    path: '/api/users',
    model: User,
    dataSource: RestifizerMongooseDataSource,
    // Example: allow filtering only on indexed fields for performance/security
    allowedFilterFields: ['username', 'email']
  }
]));

// 4. Start the Express server
app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
  console.log('To test, use a tool like HTTPie or curl:');
  console.log(`http POST http://localhost:${PORT}/api/users username='testuser' email='test@example.com'`);
  console.log(`http GET http://localhost:${PORT}/api/users`);
  console.log(`http GET http://localhost:${PORT}/api/users?filter=\"{\"username\":\"testuser\"}\"`);
});

view raw JSON →