2.0.3 • Published 5 years ago

@ryanburnette/api-cache-proxy v2.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

@ryanburnette/api-cache-proxy

Create a fetch function that is intended to be used as a caching proxy for a JSON API.

Specific to my use case.

  • caches requests to the proxied api up to maxAge which defaults to 5000 to avoid cache stampede
  • supports http basic auth as shown in example
  • body will be obj (parsed json) if JSON is returned
  • options starting with _ are stripped before being passed to request
  • minimal dependencies
var ApiCacheProxy = require('@ryanburnette/api-cache-proxy');

var fetch = new ApiCacheProxy({
  _maxAge: 5000, //default
  _basicAuth: {
    username: 'username',
    password: 'password'
  },
  headers: {
    'Content-Type': 'application/json'
  }
});

var url = 'https://jsonplaceholder.typicode.com/posts';
fetch({url})
  .then(function ({res,body}) {
    console.log(res,body);
  });
2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago