🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@ryanburnette/api-cache-proxy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ryanburnette/api-cache-proxy

A caching API endpoint proxy fetch function for my specific use case.

latest
npmnpm
Version
2.0.3
Version published
Maintainers
1
Created
Source

@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);
  });

FAQs

Package last updated on 08 May 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