diginet-core-api

1.7.8 • Public • Published

DIGINET-CORE

Build the REST API with json metadata.

This is a quick back-end system. You need create more modules, more versions, more APIs.. with only one json metadata

Table of contents

Requirements

Start MongoDB

mongod --port 27017

1. Getting started with global module

1.1 Install DIGINET-CORE
npm install -g diginet-core-api
1.2 Initial application
diginet-core-api init
1.3 Updating application
diginet-core-api update
1.4 Configuration environment
cp .env.copy .env
1.5 Start application
diginet-core-api start

2. Getting started with include as a module

2.1 Init the project package.json
npm init project-name

Open the file package.json and update tag "script"

"scripts": {
  "init": "cross-env START_WITH=init node index.js",
  "start": "cross-env START_WITH=start node index.js",
  "update": "cross-env START_WITH=update node index.js",
  "generate-doc": "cross-env START_WITH=apidoc node index.js",
  "apidoc": "npm run generate-doc && apidoc -i api/service/ -o doc/"
}

After that run command to add dependencies

npm install --save diginet-core-api
npm install --save-dev apidoc
npm install --save-dev cross-env
2.2 Create index.js file
const core = require('diginet-core-api');
const cmd = process.env.START_WITH ? process.env.START_WITH : 'start';
try {
  core(cmd);
} catch (e) {
  console.error(e);
}
2.3 Install node modules
npm install
2.4 Initial application and default handles
npm run init
2.5 Updating application if got the new version of diginet-core-api
npm run update
2.6 Configuration environment
cp .env.copy .env
2.7 Start application as development
npm run start

Now go to homepage http://localhost:3000

Use the Postman to test application

Some results for test

HTTP/1.1 200 OK

[
  {
    "gender": "male",
    "_id": "5e7115bd926d13129e9b1cdf",
    "username": "username7",
    "email": "email7@email.com",
    "password": "ssss",
    "age": 65,
    "phone": "0979737908",
    "birthday": "2020-03-17T07:06:16.664Z",
    "salary": 1500.8,
    "avatar": "https://i.pinimg.com/originals/90/b0/b3/90b0b3b15ccecf9efda592b0bdf462aa.jpg",
    "last_ip": "30.230.33.25"
  }
]

Also when doing requests, it's good to know that:

  • If you make POST, PUT, PATCH or DELETE requests, changes will be automatically.
  • Your request body JSON should be object enclosed, just like the GET output. (for example {"name": "Foobar"})
  • Id values are not mutable. Any id value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken.
  • A POST, PUT or PATCH request should include a Content-Type: application/json header to use the JSON in the request body. Otherwise it will result in a 200 OK but without changes being made to the data.

Routes

    GET     -> /*/auth/get-token (*)
    GET     -> /*/auth/refresh-token (token)
    GET     -> /*/system/get-captcha (token)
    GET     -> /v1.0.0/setting/default (token)
    GET     -> /v1.0.0/setting/init/:password (token)
    GET     -> /v1.0.0/setting/get-by-id/:id (token,admin)
    PUT     -> /v1.0.0/setting/get-all (token,admin)
    POST    -> /v1.0.0/setting/add (token,admin)
    POST    -> /v1.0.0/setting/edit (token,admin)
    DELETE  -> /v1.0.0/setting/delete (token,admin)
    DELETE  -> /v1.0.0/setting/deletes (token,admin)
    POST    -> /v1.0.0/upload/file (token)
    PUT     -> /v1.0.0/user/login (token)
    PUT     -> /v1.0.0/user/logout (token)
    PUT     -> /v1.0.0/user/login-social (token)
    PUT     -> /v1.0.0/user/admin (token)
    PUT     -> /v1.0.0/user/check-username (token)
    PUT     -> /v1.0.0/user/check-email (token)
    PUT     -> /v1.0.0/user/forgot-password (token)
    PUT     -> /v1.0.0/user/reset-password (token)
    PUT     -> /v1.0.0/user/register-user (token)
    PUT     -> /v1.0.0/user/change-password (token,login)
    PUT     -> /v1.0.0/user/send-password (token,admin)
    POST    -> /v1.0.0/user/add-child (token,login)
    GET     -> /v1.0.0/user/get-children (token,login)
    DELETE  -> /v1.0.0/user/del-child (token,login)
    POST    -> /v1.0.0/user/add-user (token,admin)
    POST    -> /v1.0.0/user/edit-user (token,login)
    GET     -> /v1.0.0/user/get-by-id/:id (token,login)
    GET     -> /v1.0.0/user/get-all (token,admin)
    PUT     -> /v1.0.0/user/active-user (token,admin)
    PUT     -> /v1.0.0/user/disable (token,login)
    DELETE  -> /v1.0.0/user/delete-user (token,admin)
    DELETE  -> /v1.0.0/user/delete-users (token,admin)

Connection the database

api/v1.0.0/database/mongo.json

{
  "driver": "mongoose",
  "connection": "mongodb://{HOST}:{PORT}/{DATABASE}",
  "options": {
    "useCreateIndex": true,
    "useNewUrlParser": true,
    "useUnifiedTopology": true,
    "serverSelectionTimeoutMS": 5000
  }
}

CLI usage

1. diginet-core-api init
2. diginet-core-api update
3. diginet-core-api apidoc
4. diginet-core-api start [options]

Options:
  --port, -p     Start app with port
  --host, -h     Start app with host
  --help         Show help                                             [boolean]
  --version, -v  Show version number                                   [boolean]

Examples:
  diginet-core-api init
  diginet-core-api update
  diginet-core-api apidoc
  diginet-core-api start -h localhost -p 3000

https://www.npmjs.com/package/diginet-core-api
Deployment

1- Install software to serve

npm install -g pm2
pm2 startup

2- Go to root application, copy and edit the environment in the process.json

cp process.json.copy process.json
pm2 start process.json
pm2 save
Build to binary lib
npm install -g pkg
npm run pack-linux | pack-mac | pack-win

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.7.82latest

Version History

VersionDownloads (Last 7 Days)Published
1.7.82
1.7.70
1.7.61
1.7.51
1.7.40
1.7.31
1.7.21
1.7.10
1.7.00
1.6.90
1.6.80
1.6.70
1.6.60
1.6.51
1.6.40
1.6.31
1.6.20
1.6.10
1.6.00
1.5.120
1.5.111
1.5.100
1.5.90
1.5.80
1.5.70
1.5.61
1.5.50
1.5.41
1.5.31
1.5.20
1.5.10
1.5.00
1.4.100
1.4.91
1.4.80
1.4.70
1.4.60
1.4.50
1.4.40
1.4.30
1.4.20
1.4.10
1.4.00
1.3.130
1.3.121
1.3.110
1.3.100
1.3.90
1.3.80
1.3.70
1.3.60
1.3.51
1.3.42
1.3.31
1.3.20
1.3.10
1.3.00
1.2.120
1.2.110
1.2.100
1.2.90
1.2.81
1.2.70
1.2.61
1.2.51
1.2.40
1.2.30
1.2.20
1.2.10
1.2.01
1.1.01

Package Sidebar

Install

npm i diginet-core-api

Weekly Downloads

23

Version

1.7.8

License

MIT

Unpacked Size

40.1 kB

Total Files

8

Last publish

Collaborators

  • rocachien