1.0.2 • Published 1 year ago

@zeelyn/http v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@zeelyn/http

Project setup

npm install @zeelyn/http

Global configuration

import http from "@zeelyn/http";
http.defaults((config) => {
            config.baseURL = "https://www.google.com";
            config.$on_before_request = (options) => {
                options.headers["Authorization"] = "Bearer " + localStorage.getItem("access_token");
            };
            config.$401 = () => {
                console.log("Request failed with status code 401");
            };
            config.$finally = () => {
                console.log("finally exec");
            };
            config.$error_network=(err)=>{
                console.error("network error ", err);
            }
        });

Request url

http.get("/api/test",{})
    .then((res) => {
        console.log("ok=>", res.data);
    })
    .catch((err) => {
        console.error(err);
    });