Skip to content

Generate CRUD controllers for your express application!

License

Notifications You must be signed in to change notification settings

randomcoffees/curdy

Repository files navigation

curdy

Generate CRUD controllers for your express application!

NPM Version Travis Build Status Coveralls NPM Downloads

Install

npm install curdy --save

Usage

Checkout the example curdy app.

Model simple.model.js

const mongoose = require('mongoose');

module.exports = mongoose.model('SimpleModel', new mongoose.Schema({
  string: String,
  number: Number,
  date: Date,
  boolean: Boolean
}, {
  timestamps: true,
}));

Controller simpleModel.controller.js

const curdy = require('curdy');
const SimpleModel = require('./simpleModel.model');

module.exports = curdy.generateController(
  SimpleModel, // Model
  {
    find: { // Find Template
      _id: 'params._id'
    },
    operation: { // Operation Template
      string: 'body.string',
      number: 'body.number',
      boolean: 'body.boolean'
    },
    render: { // Render Template
      _id: '_id',
      string: 'string',
      number: 'number',
      boolean: 'boolean'
    }
  }
);

Routes index.js

const express = require('express');
const Controller = require('./simpleModel.controller');
const router = express.Router();

const curdy = require('curdy');

router.use('/', curdy.generateRoutes(Controller));
// This creates the following routes
// GET    /       This is the showAll route, returning all models
// GET    /:_id   This is the show route, returning the model matched by the find
// POST   /       This is the create route, allowing the user to create a new model
// PUT    /:_id   This is the update route, allowing the user update a model
// DELETE /:_id   This is the delete route, allowing the user delete a model

module.exports = router;

Goals

  • Easy to install
  • Easy to override and extend
  • Make working with CRUD simpler and faster.

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.


Built with ❤️ at Hubba.

About

Generate CRUD controllers for your express application!

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •