npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@momsfriendlydevco/axiosy

v1.1.1

Published

Axios with auto-retry, logging and sensible error reporting

Downloads

77

Readme

@MomsFriendlyDevCo/Axiosy

A simple wrapper around Axios which adds some additional features:

  • Auto-retry on all outgoing requests - configure further by setting raxConfig
  • Simple logging for outgoing, retry and errored requests via @MomsFriendlyDevCo/Debug
  • New error reporting class AxiosError which includes (sane) error reporting + doesn't spew a giant recursive object to the console if you just log it
  • Log request / response to disk with a simple boolean (also adjustable via environment variable DEBUG=axiosy)

Usage

This module mutates the global Axios instance so it needs to be included once to function.

Method #0 - Update package.json to hot swap axios for this NPM

{
  ...
  "imports": {
    "axios": "@momsfriendlydevco/axiosy"
   },
  ...
}

Method #1 - Inject into global Axios instance

import axios from 'axios';
import {inject} from '@momsfriendlydevco/axiosy';

inject(); // Inject into global object

// Can now use `Axios` with above features

Method #2 - Use the packages, already injected version of Axios

import axios from '@momsfriendlydevco/axiosy';

// Can now use `Axios` with above features

Method #3 - Inject into a instanced version of Axios

import axios from 'axios';
import {inject} from '@momsfriendlydevco/axiosy';

let myAxios = inject(axios.create()); // Add to instanced object

// myAxios is now a private, injected version of Axios

API

This library follows the default Axios Request schema and returns the default Axios Response except for the following additions.

AxiosRequest.log

Log the outgoing request to the console. Enabled by default. Set to falsy to disable. If truhty (but not an object), will default to the following options:

| Option | Type | Default | Description | |------------|-----------|---------|--------------------------| | request | Boolean | true | Log requests to console | | response | Boolean | false | Log responses to console |

NOTE: Setting the environment variable DEBUG=axiosy enables both of the above for anything using the library.

AxiosRequest.debug

Write the request / response objects to disk for this request. This can be a simple true to enable both behaiours (which uses all defaults) or an object containing any of the following:

| Option | Type | Default | Description | |------------------|------------|---------|----------------------------------------------------------------------------------------------------------------------| | request | Boolean | true | Write the request to disk | | requestPath | Function | | Where to store the request, called as (request). Default is to store in OS temp directory + some request details | | requestFormat | Function | | Mutate the incoming raw AxiosRequest before saving. Called as (AxiosRequest) | | response | Boolean | true | Write the response to disk | | responseStack | Boolean | true | Omit response line if no other request has occured since | | responsePath | Function | | Where to store the response, called as (response). Default is to store in OS temp directory + some request details | | responseFormat | Function | | Mutate the incoming raw AxiosResponse before saving. Called as (AxiosResponse) | | formatter | Function | | Geneal JSON to string formatter, defaults to tabbed output |

AxiosRequest.raxConfig

Axios-Retry options.

These default to the following unless overridden per-request or by editing AxiosInstance.defaults.raxConfig.

instance.defaults.raxConfig = {
  retry: 5, // Retry 5 times on requests that return a response (500, etc) before giving up.  Defaults to 3.
  noResponseRetries: 5, // Retry 5 times on errors that don't return a response (ENOTFOUND, ETIMEDOUT, etc).
  statusCodesToRetry: [[100, 199], [400, 499], [500, 599]], // Retry everything except 2?? (OK), 3?? (redirect) codes
  backoffType: 'exponential',
};