Giter Site home page Giter Site logo

restapi's Introduction

restAPI Build Status

NodeJS API + crypto + token authentication + multidbsupport

install

  1. install nodejs (sudo apt-get update sudo apt-get install -y gcc g++ make wget http://nodejs.org/dist/node-latest.tar.gz tar -xzvf node-latest.tar.gz cd [CREATED NODE DIR] ./configure make sudo make install curl https://www.npmjs.org/install.sh | sh
  2. install mongodb (check if version >2.6.x) apt-get install mongodb
  3. clone repo & go in directory
  4. run npm install to install all dependencies (run npm install -g grunt-cli) afterwards
  5. set configs in ./config and run following commands as sudo
  6. run grunt exec:killDB
  7. run grunt exec:startFirstDB
  8. run grunt exec:createMongoUsers // creates mongo users to restrict access
  9. run grunt exec:killDB // stops all mongo services
  10. run grunt exec:startDB // start mongo session with authentication
  11. run grunt initSystem -username [sysusername] -password [syspassword] -email [sysemail] // creates systemdb with sysuser
  12. run grunt reinstall // creates/recreates test endpoint db 'test' with test data (user, admin, ...) accepts '-target' flag to allow to create a new db with testdata
  13. run grunt or grunt start to start nodejs server

After you have configured your mongo (you only need grunt reinstall and grunt)

Doc

index.js -> init server and workers (clustering) appServer.js -> express server, request handling, middleware for authentication config -> db, app, require, logging configs endpoints -> rest endpoints models -> db models (schema and model)

Models & Endpoints

  • For each model an endpoint file with the same name must exist
  • on startup all models are loaded and for all models the entpoint file
  • model registers the mongoose model with its schema
  • versioning
  • multidb support: '/api/:version/:database/:classname/id/:id/:action'
  • endpoint file returns an object with keys for each method (post, get, put, delete) as values another object with keys '', 'object', '{actionname}'. '' stands for request without objectid like '/api/user'. 'object' for a object call like '/api/v1/restAPI/user/:id' where the object is placed automatically on req.object. '{actionname}' could be used if the default methods are not enough for any purpose like GET '/api/v1/restAPI/user/id/:id/rating' or GET '/api/v1/restAPI/user/activeOnes'.
  • additional systemdb for managing/monitoring purposes (or if you need a backoffice for other dbs)
  • a model returns mongoose schema, mongo model, and optionally systemdb flag (systemdb: true -> this model is only für systemdb, systemdb: false -> only for the other dbs, not set -> for otherdbs and systemdb)

Next steps

  • grunt task for db backup (export/import)

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.