Code Monkey home page Code Monkey logo

axios-helper's Introduction

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(() => {

    });

axios-helper's People

Contributors

dependabot[bot] avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.