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-redux-client

v0.3.31

Published

πŸ“œ Client for Axios, with built-in integration for Redux.

Downloads

27

Readme

Axios Redux Client

πŸ“œ Client for Axios, with built-in integration for Redux.

npm version

πŸ’‘ This package will reduce your work when configuring Redux's environment. You will be able to make fast requests with very little configuration and it will save it directly to Redux's store. Also, it is fully compatible with hooks!

πŸ›  Installation

NPM:

npm install axios-redux-client --save

Yarn:

yarn add axios-redux-client

πŸ“ˆ Examples

Quick Start

  • index.js
import React from 'react';
import ReactDOM from 'react-dom';
import AxiosClient from 'axios-redux-client';

const useConfiguration = () =>
  return {
    queries: {
      getObjects: {
        url: '/object', method: 'GET',
      },
    },
    baseUrl: 'http://localhost:8080',
    auth: 'jwt',
};

ReactDOM.render(
  <AxiosClient useConfiguration={useConfiguration}>
    <MyComponent />
  </AxiosClient>,
document.getElementById('root'),
  • MyComponent.js
import React from 'react';
import { useQuery } from 'axios-redux-client';

const MyComponent = () => {
    const [{data}] = useQuery('getObjects');
    
    return (
    	<div>My objects = {data} </div>
    )
}

Full Config

  • index.js
import React from 'react';
import ReactDOM from 'react-dom';
import AxiosClient from 'axios-redux-client';

const useConfiguration = () =>
  return {
    queries: {
      getObjects: {
        url: '/object',
         method: 'GET', 
         idProperty: "id",
         sortComparer: (a, b) => a.name.localeCompare(b.name),
      },
      login: {
        url: '/login',
        method: 'POST',
      },
    },
    cruds: {
       crudBasic: {
        url: "/basic",
        idProperty: '_id',
        sortComparer: (a, b) => a.name.localeCompare(b.name),
      },
       crudComplex: {
           url: "/complex",
           idProperty: '_id',
           sortComparer: (a, b) => a.value - b.value,
           deleteUrl: "/complex/delete/&{id}",
       }
    },
  responseHandler = ({ response, queryName }) => response.status === 200 ? console.log(queryName + " worked!") : console.log(response)
  baseUrl: 'http://localhost:8080',
  auth: 'jwt',
};

ReactDOM.render(
  <AxiosClient useConfiguration={useConfiguration}>
    <MyComponent />
  </AxiosClient>,
document.getElementById('root'),
  • MyComponent.js
import React from 'react';
import { useQuery, useList, usePost } from 'axios-redux-client';

const MyComponent = () => {
    const [{data, loading, error}] = useQuery('getObjects');
    const [{data, error}] = useList('crudComplex');
    const [{data, loading}, post] = usePost('crudBasic');
    
    return (
    	<div>My objects = {data} </div>
    )
}

πŸ’» API

This package have the following exports:

import AxiosClient, { useQuery,  useEdit, useGet, useList, 
                     usePost, useQuery, useReadCache, useWriteCache } from 'axios-redux-client';
  • Axios Client

    Provides Axios Client Context.

    • useConfiguration - A Hook that return a Config Object.
    • children - React Node.
  • useQuery

    Hook used for base queries.

    • queryName - Query's name which was declared in the Config Object.
    • props - Props passed to the query. Available props are: manual(false if the query is executed automatically. Default: false), params (Parameters passed to query string) and options (Same as Axios options).
    Returns [{data, loading, error, response}, refetch]:
    • data - Data from response.
    • loading - True if is fetching.
    • error - Response Error.
    • response - Whole response.
  • useEdit, useGet, useList, usePost

    This hooks are used for crud queries.

    • queryName - Query's name which was declared in the Config Object.
    • props - Props passed to the query. Available props are: manual(false if the query is executed automatically. Default: false), params (Parameters passed to query string) and options (Same as Axios options).
    Returns [{data, loading, error, response}, refetch]:
    • data - Data from response.
    • loading - True if is fetching.
    • error - Response Error.
    • response - Whole response.
  • useReadCache

    Hook used for retrive data from store.

    • queryName - Query's name which was declared in the Config Object.
    • id - Entity's id, if any.
    Returns { selectedAll, selectedById }:
    • selectedAll - All data related to the query passed on parameters.
    • selectedById - If id was passed on params, it will return the data where idProperty === id.
  • useWriteCache

    Hook used for retrive data from store.

    • queryName - Query's name which was declared in the Config Object.
    Returns { selectedAll, selectedById }:
    • addOne(data) - Add entity related to queryName.
    • addMany(array) - Add an array of entities to queryName.
    • setAll(array) - Replace current entities with array passed.
    • upsertOne(data) - If entity with that id exists it will updated it, else, it will be added.
    • upsertMany(data) - Upsert an array of entities to queryName.
    • removeOne(id) - Remove from queryName by ID.
    • removeAll() - Remove all from queryName.

πŸ›  useConfiguration

The useConfiguration hook must return five objects.

  • queries - An object like:

     [queryName]: {
           url: string, \\ query's endpoint
           method: 'GET' | 'POST' | 'PUT' | 'DELETE', \\ query's method
           idProperty: string, \\ entity's identificator - not required, however if not passed it won't save to store!
           sortComparer: (a, b) => number, \\ Function to compare and sort entities - not required
        }
  • cruds - An object like:

     [queryName]: {
           url: string, \\ query's endpoint
           idProperty: string, \\ entity's identificator - not required, however if not passed it won't save to store!
           sortComparer: (a, b) => number, \\ Function to compare and sort entities - not required
           getUrl: string, \\ get endpoint - not required; default = "/url/&{id}"
           listUrl: string, \\ list endpoint - not required; default = "/url"
           postUrl: string, \\ post endpoint - not required; default = "/url/&{id}"
           deleteUrl: string, \\ delete endpoint - not required; default = "/url/&{id}"
           putUrl: string, \\ put endpoint - not required; default = "/url/&{id}"
        }
  • baseUrl - The host url.

  • responseHandler - A function which passes { response, queryName: string, jwtAuth } for handling the responses.

  • getRequestConfig - A function which passes config: AxiosRequestConfig for handling the default request configurations. Must return an AxiosRequestConfig.

πŸ—ƒ Changelog

  • 0.2.0
    • Removed Config
    • Added useConfiguration for use hooks in responseHandler and getRequestConfig
  • 0.1.2
    • Request and Response Logging
    • Removed JWT Auth and implemented getRequestConfig
    • Bug Fixes
  • 0.1.1
    • Bug Fixes
  • 0.1.0
    • First release!
  • 0.0.1
    • WIP

πŸ“‹ About

Gabriel Vinhaes de Lima – @kvlao – [email protected]

License: MIT

https://github.com/Gabrielgvl/axios-redux-client