1.10.0 • Published 3 years ago

iblokz-rest-api v1.10.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

iBlokz / REST API

Generates a rest api with mongodb middleware from a json file

Install

npm install iblokz-rest-api

Basic Usage

  • server.js
// dependencies
const express = require('express');
const mongoose = require('mongoose');

// rest api
const restApi = require('iblokz-rest-api');
const restMap = require('./rest.json');

// create app and db instances
const app = express();
const db = mongoose.connect('mongodb://localhost/rest_api_example');

// loads the models from json schema
restApi.loadModel(restMap, db);


// initis rest endpoints
restApi.initRoutes(app, restMap, {}, db);
  • rest.json
{
	"collections": {
		"users": {
			"model": "User",
			"schema": {
				"name": "String",
				"email": { "type":"String", "isEmail":true, "unique": true},
				"password": "String"
			}
		},
		"articles": {
			"model": "Article",
			"schema": {
				"title" : { "type": "String", "required": true, "minLength": 1, "maxLength": 5, "unique": true },
				"viewCount": { "type": "Number", "min": 1},
				"body" : "String",
				"createdBy" : { "type": "ObjectId", "ref":"User", "required": false},
				"dateCreated": { "type": "Date", "default": "Date.now" }
			}
		}
	},
	"routes": {
		"api" : {
			"_meta": {
				"virtual": true,
				"crud": true,
				"contentType": "json"
			},
			"users": {},
			"articles": {}
		}
	}
}

API

  • lib/index.js - loadModel (map, db) // parses and loads all schemas from the restMap into mongoose models - initRoutes (app, map, ctrl, db) // generates the RESTful API endpoints with crud functionality
  • lib/crud/middleware.js
  • lib/route/auth.js
  • lib/route/builder.js
  • lib/schema/parser.js
  • lib/schema/validator.js
1.10.0

3 years ago

1.9.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago