# @ryanburnette/api-cache-proxy

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

Latest version **2.0.3** (published 2019-05-08) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @ryanburnette/api-cache-proxy
pnpm add @ryanburnette/api-cache-proxy
yarn add @ryanburnette/api-cache-proxy
bun add @ryanburnette/api-cache-proxy
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2019-05-08 |
| First published | 2019-05-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ryan Burnette |
| Maintainers | ryanburnette |

## Links

- npm: https://www.npmjs.com/package/@ryanburnette/api-cache-proxy
- Repository: https://code.ryanburnette.com/ryanburnette/api-cache-proxy
- npm.io page: https://npm.io/package/@ryanburnette/api-cache-proxy

## Dependencies (2)

- [@root/request](https://npm.io/package/@root/request.md) ^1.3.10
- [@ryanburnette/merge-options](https://npm.io/package/@ryanburnette/merge-options.md) ^2.0.0

## Recent versions

- 2.0.3 (latest) — 2019-05-08
- 2.0.2 — 2019-05-07
- 2.0.1 — 2019-05-07
- 2.0.0 — 2019-05-07
- 1.0.0 — 2019-05-07

## README

# [@ryanburnette](https://ryanburnette.com)/[api-cache-proxy](https://www.npmjs.com/package/@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

```js
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);
  });
```

---
_Source: https://npm.io/package/@ryanburnette/api-cache-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
