0.0.9 • Published 6 years ago

moncrud v0.0.9

Weekly downloads
3
License
Beerware
Repository
github
Last release
6 years ago

MonCRUD

Easily generates RESTfull APIs using a MongoDB database.

This node module creates resources from Mongoose models and exposes them using an Express server.

Instalation

npm install moncrud

Usage

First, have a Mongoose Model:

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database', {useNewUrlParser: true});

const UserSchema = new mongoose.Schema({
    name: String,
    email: String
});

const User = mongoose.model("User", UserSchema)

Decorate your express app with moncrud

const moncrud = require('moncrud')
const express = require('express')
const baseApp = express()

//
// Perform additional configurarions on express instance
//

// Decorate with moncrud
const app = moncrud(baseApp)

Alternatively, you can just have moncrud set everything up for you

const moncrud = require('moncrud')
const app = moncrud() 

Then tell MonCRUD to automatically generate a RESTfull resource for your Model:

// Default route is Model name in lowercase. In this case, '/user'
app.addCrud(User)

// Or you can customize your routing
app.addCrud(User, '/admins')

// You can also add a lot of models all at once (default routings will be applyed)
app.addCruds([
    User,
    Product,
    Store,
    Supplier
])


// Start up your express server!
app.listen(3000);

You can then got to http://localhost:3000/user to:

Create an user

POST http://localhost:3000/user

{
    "name":"lukita",
    "email","lukita@email.com"
}

Read an user

GET http://localhost:3000/user/:id

Read all users

GET http://localhost:3000/user

Read from all users with filters

GET http://localhost:3000/user?name=lukita

Update an user

PATCH http://localhost:3000/user/:id

{
    "email","lukita@new_email.com"
}

Delete an user

DELETE http://localhost:3000/user/:id

Overwrite an user

PUT http://localhost:3000/user/:id

{
    "name":"lukita v2",
    "email","lukita@newer_email.com"
}
0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago