h5-http
v1.0.1
Published
支持加密请求
Downloads
0
Readme
bk-h5-http
安装
npm i bk-h5-http
简单使用
import create from './h5-http'
const { http } = create({
baseURL: '',
timeout: 1000,
cryptoConfig: {
type: 'AES',
secretKey: 'bk__aa'
}
})
http.request(config);
http.get(url[, data[, config]]);
http.post...
使用
import { create } from "bk-h5-http";
// 设置默认参数
const http = create({
baseUrl: "http://abc.com/",
timeout: 2000,
cryptoConfig: {
type: "MD5" | "AES" | "DES" | "SHA1" | "SHA256" | "SHA224" | "SHA512" | "SHA3";
secretKey: string;
cfg: {};
};
unEncryt: boolean;
});
拦截器
// 请求拦截器
http.interceptors.request.use((config) => {
return config;
});
// 响应拦截器
http.interceptors.response.use((res) => {
// 自定义错误
if (res.code !== 200) {
return Promise.reject(new Error("Request Error"));
};
return res;
}, (error) => {
const { message, response, config } = error;
return Promise.reject(error);
});