Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-data-store

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-data-store

API Data Store

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
492
decreased by-12.61%
Maintainers
1
Weekly downloads
 
Created
Source

api-data-store

API Data store

A Data Store that will run the same API endpoint once, cache results, and expire after a timeout.

Basic Usage

import axios from 'axios';
import ApiDataStore from 'api-data-store';

const users = await ApiDataStore.fetch('/api/v1/users', {
  fetchMethod: axios.get,
});

Setting a global fetch method

import axios from 'axios';
import ApiDataStore from 'api-data-store';

ApiDataStore.setFetchMethod(axois.get);

const users = await ApiDataStore.fetch('/api/v1/users');

Caching results in the default localStorage driver

import axios from 'axios';
import ApiDataStore from 'api-data-store';

ApiDataStore.setFetchMethod(axois.get);

const users = await ApiDataStore.fetch('/api/v1/users', {
  cache: true,
});

Setting a prefix for local storage

ApiDataStore.setPrefix('your-api-name:');

// local storage:
// your-api-name:/api/v1/users = { ...data }

Setting a timeout on the cache in milliseconds

const users = await ApiDataStore.fetch('/api/v1/users', {
  cache: true,
  timeout: 1000 * 60 * 5 // 5 minutes
});

Using an in memory custom storage driver

The API Data Store uses the localStorage interface. If you need to create your own custom storage driver use the same methods as localStorage.

import axios from 'axios';
import ApiDataStore from 'api-data-store';
import MemoryDataStore from 'api-data-store/memoryDataStore';

ApiDataStore.setFetchMethod(axois.get);
ApiDataStore.setStorageDriver(MemoryDataStore);

const users = await ApiDataStore.fetch('/api/v1/users', {
  cache: true,
  timeout: 1000 * 60 * 5 // 5 minutes
});

FAQs

Package last updated on 16 Oct 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc