New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@appello/axios-offline

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appello/axios-offline

Store query and repeat

latest
npmnpm
Version
1.0.14
Version published
Maintainers
0
Created
Source

@appello/axios-offline

npm package License: MIT

Remembering failed requests and repeating when an internet connection is available

Credentials

This package is based on a work of jonkofee.

Installation

Using npm

npm install axios localforage # install peer dependencies
npm install @appello/axios-offline

Using yarn

yarn add axios localforage # install peer dependencies
yarn add @appello/axios-offline

Usage example

import axios, { AxiosAdapter } from 'axios';
import { AxiosOffline } from '@appello/axios-offline';
import NetInfo from '@react-native-community/netinfo';
import LocalForage from 'localforage';

const offlineUrls = ['/list', '/profile'];

export const axiosOfflineInstance = new AxiosOffline({
  defaultAdapter: axios.defaults.adapter as AxiosAdapter, // require, basic adapter
  storageOptions: {
    name: 'axios-offline', // optional, default: "axios-stack"
    driver: LocalForage.LOCALSTORAGE, // optional, default: LocalForage.LOCALSTORAGE
  },
  shouldStoreRequest: config => {
    return config.method === 'POST' && offlineUrls.includes(config.url as string);
  },
  getResponsePlaceholder: config => ({
    config,
    headers: {},
    data: undefined,
    status: HttpStatusCode.Ok,
    statusText: 'Request successfully stored till back online!',
  }),
});

export const Api = axios.create({
  adapter: axiosOfflineInstance.adapter,
});

window.addEventListener('online', (event) => {
  axiosOfflineInstance.sendRequestsFromStore();
});

Keywords

axios

FAQs

Package last updated on 06 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts