0.0.9 • Published 7 years ago

mexp v0.0.9

Weekly downloads
2
License
ISC
Repository
-
Last release
7 years ago

基于Express搭建的Rest接口开发框架

基于Express开发的接口服务开发框架 用于快速开发接口、采用sql model配置文件的形式加载接口

依赖:

  • mysql
  • express
  • bodyParser
  • cors
  • helmet
  • morgan

使用

安装

npm install mexp --save

使用

//index.js

var mexp=require('mexp');

//注册配置文件	
mexp.config({path,name});

//注册model
mexp.model(dirString);

//注册路由
mexp.route(function(app){app.use('/')});

//启动服务	
mexp.boot()    

启动项目

node index.js

API

#### config(params):加载配置文件

param:[String|Object] 
String:目录扫描
Object{path,name}:文件地址、和文件名称

model(params):加载model配置文件

params:String model配置文件的目录、系统会自动扫描下面的文件

暂时 route(params):回调的形式传回app对象

params:Function 
回调参数:express实例对象

cors(...params1,params2):启用cors配置

safe():启动默认的安全配置

boot():启动服务

model配置说明:

现在基于文件名称来区分业务模块:user.json

{
	key:{
            name:"接口名称",
            sql:"sql字符串",
            path:"",
            query:""
        }
}

key 接口前缀路径,如:GET#/user

name 接口名称、非必填项

sql sql字符串、必填

path 路径查询字段数组、非必填项

query url查询字段数组、非必填项

Demo

目录结构:

Project

	configs

		--database.json

	models

		--modelA.json		

	--index.js

	--package.json

安装mexp

npm install mexp --save

代码:

var path = require("path");
var mexp = require("mexp");

var dir = path.resolve(__dirname, './models');
var file = path.resolve(__dirname, './configs/database.json');

mexp.model(dir);
mexp.config({ path: file, name: "database" });


mexp.route(function (app) {
	app.use('/test', function (req, res) {
    	res.json({message:"hello"});
	});
});

mexp.boot();

启动项目:

node index.js --port 3000

访问:

http://localhost:3000

可以看到可用的api接口列表

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

1.0.0

7 years ago