0.3.7 • Published 4 years ago

acme-fetch v0.3.7

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

acme-fetch

是什么

基于 fetch 封装的配置化请求库;

已完成的功能

  1. 基本请求封装
  2. HTTP 状态检查
  3. 支持 fetch 请求 Abort
  4. 支持 timeout 超时自动取消请求
  5. LRU 淘汰缓存策略

Example

// 安装acme-fetch
npm install acme-fetch -D

// import本库并实例化传入基本全局的配置, 仅展示部分API
const fetch = new AcmeFetch({
  baseUrl: 'http://172.0.0.1:8080/',
  defalutParams: { token: '123' },
  defaultOptions: { timeout: 1000, cache: true }
});

// 基本请求方法
fetch.createRequest('/user/add', {user: 'zs'}, {
  method: 'POST'
}).then((res) => {
  return res.json();
}).then((data) => {
  console.log(data);
})

// 发送一个get请求并直接获取data
fetch.getData('/user/queryDetail');

// 发送一个post请求并直接获取data
fetch.postData('/user/queryDetail', {userId: '1'});

// abort请求
fetch.postData('/user/queryDetail', {userId: '1'}, {canAbort: true});
fetch.getAortController('/user/queryDetail').abort();

// 缓存请求数据
fetch.postData('/user/queryDetail', {userId: '1'}, {canAbort: true, cache: true});
fetch.getCacheData('/user/queryDetail');
0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.2

4 years ago

0.3.3

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago