interfacerequest
v0.0.25
Published
#### 配置 ``` import {HttpRequestConfig} from "interfacerequest"; import {IHttpUtilsFilter} from "interfacerequest"; import {IFilterExeFinish} from "interfacerequest"; import {IBaseBeanRequest} from "interfacerequest"; import {ABaseBeanResponse} from "inter
Downloads
7
Readme
JS使用
配置
import {HttpRequestConfig} from "interfacerequest";
import {IHttpUtilsFilter} from "interfacerequest";
import {IFilterExeFinish} from "interfacerequest";
import {IBaseBeanRequest} from "interfacerequest";
import {ABaseBeanResponse} from "interfacerequest";
import {INetStatusListener} from "interfacerequest";
import {ISpecialCodeHandler} from "interfacerequest";
import {HttpRequestUtil} from "interfacerequest";
import {IEncryptData} from "interfacerequest";
import {IProxy} from "interfacerequest";
import {IOriginRequest} from "interfacerequest";
import {HttpRequestManager} from "interfacerequest";
import {ABaseHttpCallBack} from "interfacerequest";
/************************************** 功能示例 *****************************************/
class MBaseResponse extends ABaseBeanResponse{
getReturnCode (bean) {
return bean.returnCode;
}
getReturnErrorMsg (bean) {
return bean.returnMessage;
}
getSuccessReturnCode () {
return "0000";
}
setCustomSuccessRule(bean) {
return "0000"===bean.returnCode
}
}
const defaultConfig = new HttpRequestConfig();
HttpRequestManager.setDefaultHttpConfig(defaultConfig);
defaultConfig
.showLog(false)
.requestDataKey("data")
.responseDataKey("data")
.addBeforeRequestFilter({
exeFilter: function (iFilterExeFinish, filterParams) {
iFilterExeFinish.toRequest({"token": "safsadfdsfsa"})
}
,
flag: function (flag) {
},
matchUrl: function (url) {
return true
}
}
)
.baseResponseBean(new MBaseResponse())
.baseRequestBean({
baseParams: function () {
return {
"time": "2021-01-02",
"device": "android",
"uuid": "xxdfsdfsdfsafds",
};
}
});
// .addSpecialReturnCode("0000",new class implements ISpecialCodeHandler {
// handlerSpecialCode(httpUtils: HttpRequestUtil, response: {}): boolean {
// console.log("特殊状态码");
// console.log(response);
// return false;
// }
// });
调用接口
import {HttpRequestManager, ABaseHttpCallBack} from "interfacerequest"
console.log("开始请求6");
HttpRequestManager.get()
.load("http://localhost:9001/pkyingyu/pub/login")
.param({
"phone": "15026466775",
"password": "AAA",
})
.post(new class extends ABaseHttpCallBack {
onFail(stateCode, returnMsg) {
console.log(stateCode, returnMsg);
}
onSuccess(responseBean) {
console.log("success", responseBean);
}
});
TS使用
略