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 🙏

© 2025 – Pkg Stats / Ryan Hefner

axios-helper-kit

v1.1.0

Published

A TypeScript-based Axios wrapper for API calls with optional toast notifications

Readme

axios-helper-kit

A TypeScript-based Axios wrapper for API calls, with optional toast notifications via react-toastify. Supports both React and non-React projects.

Features

  • Factory function createAPI() for easy API client creation
  • Optional Authorization: Bearer <token> header injection
  • Optional toast notifications on success/error (configurable with custom messages)
  • Exposes common HTTP methods: get, post, put, delete (returns res.data only)
  • Exports types for configuration
  • Exports APIToastContainer component for React projects
  • Works in both React and non-React projects (toast is a peer dependency)

Installation

npm install axios-helper-kit axios react-toastify

Usage

1. Basic API Client

import { createAPI } from "axios-helper-kit";

const api = createAPI({ baseURL: "https://api.example.com" });

// Usage
const data = await api.get("/users");

2. With Auth Token

const api = createAPI({
  baseURL: "https://api.example.com",
  getToken: () => localStorage.getItem("token"),
});

3. With Toast Notifications (React projects)

⚠️ IMPORTANT: You MUST import the CSS and render the APIToastContainer component!

import { createAPI, APIToastContainer } from "axios-helper-kit";
import "react-toastify/dist/ReactToastify.css"; // 🚨 REQUIRED CSS IMPORT

const api = createAPI({
  baseURL: "https://api.example.com",
  withToast: true,
});

// In your app root:
function App() {
  return (
    <>
      {/* 🚨 REQUIRED: Place APIToastContainer ONCE in your app root */}
      <APIToastContainer />
      {/* Your app content */}
      <div>Your app content...</div>
    </>
  );
}

4. Custom Toast Messages

const api = createAPI({
  baseURL: "https://api.example.com",
  withToast: true,
  successMessage: "Operation completed successfully! ✅",
  errorMessage: "Something went wrong! ❌",
  // Or use functions for dynamic messages
  successMessage: (response) => `Success: ${response.data.message}`,
  errorMessage: (error) =>
    `Error: ${error.response?.data?.message || error.message}`,
});

5. Toast Options

const api = createAPI({
  baseURL: "https://api.example.com",
  withToast: true,
  toastOptions: {
    position: "top-right",
    autoClose: 5000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    theme: "light",
  },
});

6. Non-React Projects

You can use the API client without enabling withToast:

const api = createAPI({
  baseURL: "https://api.example.com",
  withToast: false, // No toast notifications
});

API

createAPI(config: CreateAPIConfig): API

CreateAPIConfig

  • baseURL: string (required)
  • getToken?: () => Promise<string | undefined> | string | undefined (optional)
  • withToast?: boolean (optional, default: true)
  • successMessage?: string | ((res: AxiosResponse) => string) (optional)
  • errorMessage?: string | ((err: any) => string) (optional)
  • toastOptions?: ToastOptions (optional)
  • deduplicateToasts?: boolean (optional, default: true)

API methods

  • get<T>(url, config?) - GET request
  • post<T>(url, data?, config?) - POST request
  • put<T>(url, data?, config?) - PUT request
  • delete<T>(url, config?) - DELETE request
  • instance - Direct access to the underlying Axios instance

All methods return res.data only (not the full response object).

Components

APIToastContainer

React component that renders the toast container. Must be placed in your app root.

import { APIToastContainer } from "axios-helper-kit";

// Basic usage
<APIToastContainer />

// With custom props
<APIToastContainer
  position="bottom-right"
  autoClose={3000}
  theme="dark"
/>

Requirements for Toast Notifications

  1. Install react-toastify: npm install react-toastify
  2. Import CSS: import 'react-toastify/dist/ReactToastify.css';
  3. Render component: <APIToastContainer /> in your app root
  4. Enable toasts: withToast: true in createAPI config

Responsibility

  • This package: API logic, token injection, toast triggering, and type safety
  • You: Import the CSS and place <APIToastContainer /> in your React app root

License

MIT