h5-http
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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);
});

请求

http.request(config)
http.get(url[, data[, config]])
http.post(url[, data[, config]])
http.put(url[, data[, config]])
http.delete(url[, config])
http.head(url[, config])
http.options(url[, config])
http.connect(url[, config])

Readme

Keywords

Package Sidebar

Install

npm i h5-http

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

14.5 kB

Total Files

8

Last publish

Collaborators

  • amaoy