xyj-res
v1.0.1
Published
res
Downloads
3
Readme
#xyj-res
##install
npm install xyj-res
##usage
const express = require('express');
const xRes = require('xyj-res');
let app = new express();
app.use(xRes);
##res.api
res.api('请求成功这是响应');
####客户端收到的响应
{"data":"请求成功这是响应","status":{"code":0,"msg":"request success"}}
##res.error
let data = {
code: 10001,
msg: 'test error',
data: '可选',
}//服务器自定义错误代码和描述
res.error(data);
//res.error(); //如果不传入status,则会默认返回{"code":99999,"msg":"system error"}
####客户端收到的响应
{"data":"这是一个错误","status":{"code":10001,"msg":"test error"}}
//{"data":"这是一个错误","status":{"code":99999,"msg":"system error"}}