@haisto/axios-helper
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Axios Helper Lib

GitHub stars GitHub forks GitHub watchers GitHub followers

GitHub issues GitHub license GitHub last commit GitHub release npm version npm downloads GitHub repo size in bytes HitCount language

  • How to use this lib ?
npm i @itning/axios-helper
import {AxiosHelperConfig, Patch} from "@itning/axios-helper";
// Config message toast when net error.
AxiosHelperConfig.errorMsgImpl = {
    showErrorToast(title, data) {
        console.log(title + data.msg);
        setTimeout(() => {
            AxiosHelperConfig.onceMsgFinish();
            console.log('one message show finish')
        }, 2000);
    }
};
// Config interceptor for each request or response.
AxiosHelperConfig.axiosInstanceBuilder
    .requestInterceptor({
        onFulfilled: request => {

        },
        onRejected: error => {

        }
    })
    .responseInterceptor({
        onFulfilled: response => {

        },
        onRejected: error => {
            
        }
    })
    .build();
// You can use this api to send http patch request.
// Other http request
//Get("http://api.localhost.com")
//Delete("http://api.localhost.com")
//Post("http://api.localhost.com")
//Put("http://api.localhost.com")
Patch("http://api.localhost.com")
    // Config http success code,default 200.
    .withSuccessCode(200)
    // Config whether to open error message, defalut true.
    .withEnableErrorMsg(false)
    // Config error message title, defalut '错误'.
    .withErrorStartMsg("")
    // Invoke function when error happen.
    .withErrorHandle((error) => {

    })
    // Only show once msg
    .withOnceMsg()
    // Send http request with form data.
    .withFormData({"id": "1"})
    // Send http request with url search param data.
    .withURLSearchParams({})
    // Send http request with json data.	
    .withJson({1: 1})
    // When server response received will call this function.
    // Must call this function and will send http request.
    .do(response => {

    })
    // When do function invoked.
    .doAfter(() => {

    });

Readme

Keywords

Package Sidebar

Install

npm i @haisto/axios-helper

Weekly Downloads

1

Version

1.0.0

License

Apache-2.0

Unpacked Size

87.9 kB

Total Files

117

Last publish

Collaborators

  • haisto