Coder Social home page Coder Social logo

vqrest's Introduction

VQREST

VQRest allows with one line of code create mongoose models and restful API.

Init

const vqrestApp = require('vqrest')('<mongodb-url>');

vqrestApp.create(resourceName, resourceModel, options)

Creates a mongoose scheme for mongodb and sets up restful paths for common operations:

GET /options.base/resourceName
GET /options.base/:itemId
POST /options.base/resourceName
PUT /options.base/resourceName/:itemId
DELETE /options.base/resourceName/:itemId


vqrestApp.create('user', {
    firstName: String,
    lastName: String
}, {
    base: 'api',
    getItem: {
        // prehook will always run in the very beginning
        prehook: (req, res) => new Promise(resolve => {
            if (req.user) {
                return resolve();
            }

            return res.status(401).send('Log in');
        });
        // overwrites the default behaviour
        customFn: (Model, params, query, body, user) => new Promise((resolve, reject) => {

        }
    }
    deleteItem: {
        soft: true
    }
});

vqrestApp.utils

updateObject(obj, data)

Copies corresponding fields from data to obj

    const obj = { field1: 1, field2: 2 };

    vqrestApp.utils.updateObject(obj, { field1: 2, field3: 3 });

    console.log(obj);
    // { { field1: 2, field2: 2, field3: 3 } }

vqrest's People

Contributors

adrianbarwicki avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.