0.5.3 • Published 5 years ago

@react-kit/http v0.5.3

Weekly downloads
1
License
-
Repository
-
Last release
5 years ago

react-kit/http


基于Promise的HTTP请求工具

特点

  • 支持 angular、react、vue 使用
  • 基于 axios 封装,更友好的调用方式
  • 使用 typescript 编写,内置 ts 声明文件 在编译器下获得友好的代码提示
  • 内置拦截器,处理 POST 和 PUT 下 FORM 表单形式提交的参数处理
  • 更友好的响应参数格式
  • 支持外部继续叠加 自定义拦截器
  • 不污染原生 axios API

示例

import {httpInstance, httpService} from '@react-kit/http';

// GET请求
httpService.get('/test', {a: 1, b: 2}).then(res => {
   if (res.flag) {
       // 正确的请求
   } 
});
// POST请求
httpService.post('/test', {a: 1, b: 2}).then(res => {
   if (res.flag) {
       // 正确的请求
   } 
});
// PUT请求
httpService.put('/test', {a: 1, b: 2}).then(res => {
   if (res.flag) {
       // 正确的请求
   } 
});
// DELETE请求
httpService.delete('/test', {a: 1, b: 2}).then(res => {
   if (res.flag) {
       // 正确的请求
   } 
});
// 带请求类型的请求
httpService.request('GET', '/test', {a: 1, b: 2}).then(res => {
   if (res.flag) {
       // 正确的请求
   } 
});

// 自定义拦截器,注意(后面定义的先执行,前面定义的后执行)
// 请求拦截器
httpInstance.interceptors.request.use((config => {
   return config;
}));
// 响应拦截器
httpInstance.interceptors.response.use((config => {
    return config;
}));
0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.1-rc.8

5 years ago

0.1.1-rc.6

5 years ago

0.1.1-rc.5

5 years ago

0.1.1-rc.4

5 years ago

0.1.0

5 years ago

0.0.5-rc.4

5 years ago

0.0.5-rc.3

5 years ago

0.0.5-rc.2

5 years ago

0.0.5-rc.1

5 years ago

0.0.1

5 years ago