1.1.11 • Published 4 years ago

axios-post-cache v1.1.11

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Description

This is a straight forward wrapper for caching axios requests. It curently supports post and get requests.

Installation

npm install --save post-cache or yarn add post-cache

Usage

Instantiate

You can use the axios itself or an instance as the first parameter. The second parameter must be an array of objects and/or strings. It will be used to filter the the urls that will be cached. If you use an object, it must have at least an url attribute. The params will be added to the key and will be used to differ the requests. The queryParams are extracted from the config.params, while the bodyParams are extracted from the request body. Notice that we will check if the url in the cachedUrls is contained in the request's url. Therefore 'api.my-api.com' would match both 'api.my-api.com/info' and 'api.my-api.com/super-info'

const axios = require('axios')
const PostCache = require('post-cache')

const cachedUrls = [
    {
      url: 'api.my-api.com/info',
      queryParams: ['queryExample'],
      bodyParams: ['bodyExample']
    },
    'api.my-api.com/super-info'
  ]

const postCache = PostCache(axios, cachedUrls)

Post Request

postCache.post(url, body, options)

URL

The Url will be verified to be cached or to get from the cache

Body

the request's body

Options

The request's options

Get Request

postCache.get(url, config)

URL

The Url will be verified to be cached or to get from the cache

config

The request's config

1.0.9

4 years ago

1.0.8

4 years ago

1.0.11

4 years ago

1.1.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago