0.1.16 • Published 3 years ago

very-axios v0.1.16

Weekly downloads
67
License
-
Repository
github
Last release
3 years ago

very-axios

中文 README

A convinient and uniform way to code with axios.

Features

  • provide instace methods GET/POST/PUT/DELETE/FORMDATA with uniform params
  • custom error handler function when request is failed(switchable)
  • error tips of 400/401/403/404/405/413/414/500/502/504 in both English and Chinese
  • hooks
    • beforeHook(config) for custom operations before request, such as adding a loading div
    • afterHook(responce/error, isError) for custom operations after response:such as canceling loading, process response
  • custom error handlers by status: such as redirecting to specific page when 403
  • error info in 200 response data

    • specify getResStatus(resData) to get status
    • specify getResErrMsg(resData) to get error message
    • specify getResData(resData) to get true response data
  • configure to cancel duplicate requests

    • in the new VeryAxios instance, configure cancelDuplicated: true to enable cancellation of duplicate requests
    • in the new VeryAxios instance, configure duplicatedKeyFn function to generate a duplicate key
    • customize the duplicate key duplicatedKey of a single request when requesting

基础用法

可以通过以下方法new一个VeryAxios的实例,第一个参数veryAxiosConfigvery-axios的配置,第二个参数axiosConfig为axios所支持的配置。

// request.js
const request = new VeryAxios(veryAxiosConfig, axiosConfig)

veryAxiosConfig 支持以下配置:

{
  // whether or not show tips when error ocurrs
  tip: true, // default
  // how to show tips
  tipFn: () => {},
  errorHandlers: {
    // support 400/401/403/404/405/413/414/500/502/504/any other cutom errorno
  },
  // error msg language: 'zh-cn'/'en'
  lang: 'zh-cn', // default
  // some operation before request send
  beforeHook: (config) => {},
  // some operation after response is recieved
  afterHook: (responce/error, isError) => {},
  // function to get errno in response
  getResStatus: (res) => res.errno, // default
  // function to get err message in response
  getResErrMsg: (res) => res.errmsg, // default
  // function to get data in response
  getResData: (res) => res.data, // default
  // whether to enable cancellation of duplicate requests
  cancelDuplicated: false, // default
  // function of how to generate a duplicate key
  duplicatedKeyFn: (config) => `${config.method}${config.url}` // default
}
0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

4 years ago

0.2.0

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago