0.0.6 • Published 2 years ago

axios-tracker v0.0.6

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

axios-tracker

This package allows you to track all requests and responses made with axios and collect them in one place. It will only gather the information that is useful to you, such as the endpoint, data, status, statusCode, etc.

Installation

npm install axios-tracker

Usage

import axios from "axios";
import axiosTracker from "axios-tracker";

const client = axios.create();

client.interceptors.request.use((config) => {
    config["axios-tracker"] = { track: true };
    return config;
});

const trackedClient = axiosTracker(client, (data) => {
    // data will contain the request, response, start time, and end time
    console.log(data);
});

trackedClient
    .get("/test")
    .then((response) => {
        // Handle success
    })
    .catch((error) => {
        // Handle error
    });

API

axiosTracker(axios: AxiosInstance, callbackFn: (data: any) => void)

Takes in an axios instance and a callback function to handle the gathered data.

axios.defaults.axios-tracker = { track: true }

You can also set axios-tracker to true in axios.defaults to track all requests by default.

Warning

This is a work in progress. It is not ready for production use. All risks are on you.

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago