# Monami :heart: Mongoose API Middleware for Express # Testing run `npm test` to run da testz! # How to use this dude simple rest server within seconds!!!! ```js var Mongoose = require('mongoose'); var monami = require('./monami'); Mongoose.connect("mongodb://localhost/monami_spec_tests"); require('../test/models')(Mongoose); monami(Mongoose).listen(8080); // You can mount it to your app by using // app.use('/api', monami(Mongoose)); ``` # Overrides Monami accepts method overrides. why? lets say you never want to remove data from your DB. this magic happens inside the `reopen(modelName, overrides)` or `reopen(overrides)` function. ```js var mon = monami(Mongoose); mon.reopen({ destroy: function(req, res) { req.model.findByIdAndUpdate(req.params.modelId, { $set: { deletedAt: Date.now() } }, function(err, data) { res.send("DELETED!!!!"); // LIES. }); } }); ``` You might have realized a couple of things: - Monami will inject the model you need to use to `req.model` - Monami uses the naming convetions of rails-style rest apps. (`index`, `show`, `destroy`, `insert`, `update`) # API in short ## `var mon = monami(Mongoose)` Creates an express app you can mount in your express app with all the resty stuff in it. ## `mon.reopen(modelName, overrides)` Overrides the rest methods being called to that model. ```js mon.reopen('User', { index: function(req, res) { return res.status(500).send({ error: "cannot get user list." }); } }); ``` ## `mon.reopen(overrides)` Overrides the default rest methods ```js mon.reopen({ update: function(req, res) { return res.status(404).send({ error: "there is no update on this app!!!! haha" }); } }); ``` ## Available rest methods `index`, `show`, `destroy`, `insert`, `update` # Future - Using plain MongoDB client instead of Mongoose? - Make the override methods use the error handling methods. - Make the ability to override the error handling methods. - Add "head" or other http methods? # Contribution you know the deal. - Fork. - Clone & Run tests - Branch - Write code - Test - Commit - Pull Request - $$$.