2.0.0 • Published 3 years ago

orcrist-request v2.0.0

Weekly downloads
20
License
ISC
Repository
-
Last release
3 years ago

orcrist request Ajax 请求功能组件

Update Log

  • v1.9.x 添加 FormData 文件上传兼容处理
  • v1.8.x 添加默认请求 30s 熔断功能
  • v1.5.x 添加接口 500 异常处理

Install

npm install --save orcrist-request

Usage

Default JSON Content-Type: application/json

import request from "orcrist-request";
// GET
const reqPromise = request("http://www.test.com/api/citys", {
  method: "get", // post 兼容大小写
  body: {
    foo: "bar",
  }, // Body数据部分会自动拼接至URL后
});

// POST
const req2Promise = request("http://www.test.com/api/citys", {
  method: "POST", // post 兼容大小写
  body: {
    foo: "bar",
  },
});

reqPromise.then((data) => data).catch((error) => console.error(error));
reqPromise2.then((data) => data).catch((error) => console.error(error));

FormData ver. (文件上传)

// POST
const formReqPromise = request("http://www.test.com/api/fileUpload", {
  method: "POST", // post 兼容大小写
  type: "FORM", // form 兼容大小写
  body: {
    files: {}, // dom -> files[0]
  }, // formData.append('files', {})
});

formReqPromise.then((data) => data).catch((error) => console.error(error));

API

参数说明类型默认值
url请求 URLString
option操作ObjectOption Object
handle控制ObjectHandle Object

Option Object

参数说明类型默认值可选值
method请求方法类型String'get''get' / 'post'
type发送数据类型String'json''json' / 'form'
headers自定义请求 Header 头信息Object
body请求发送数据Object

Handle Object

参数说明类型默认值
timeout请求 API 熔断超时限制,单位秒Number30
2.0.0

3 years ago

1.9.0

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago