# http-cache-to-mongo

> Cache http responses to mongodb to reduce requests to a web service api.

Latest version **1.1.1** (published 2018-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install http-cache-to-mongo
pnpm add http-cache-to-mongo
yarn add http-cache-to-mongo
bun add http-cache-to-mongo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-09-15 |
| First published | 2018-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 (+25 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Rey Arqueza |
| Maintainers | reyarqueza |
| Keywords | http, rest, api, mongodb |

## Links

- npm: https://www.npmjs.com/package/http-cache-to-mongo
- Repository: https://github.com/reyarqueza/http-cache-to-mongo
- Homepage: https://github.com/reyarqueza/http-cache-to-mongo#readme
- Issues: https://github.com/reyarqueza/http-cache-to-mongo/issues
- npm.io page: https://npm.io/package/http-cache-to-mongo

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [assert](https://npm.io/package/assert.md) ^1.4.1
- [mongodb](https://npm.io/package/mongodb.md) ~3.0.11

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-09-15
- 1.0.4 — 2018-09-15
- 1.0.3 — 2018-09-08
- 1.0.2 — 2018-05-22
- 1.0.0 — 2018-05-22

## README

# Http Cache To Mongo

## Introduction

The **http-cache-to-mongo** module allows you to store an http response into mongodb. This can be useful for reducing requests to an external http api / web service. 

The first time you make a call to a web service, **http-cache-to-mongo** will first check if that data already exists in your mongo database based on its url.

If the data for that url does not exist in your mongo database, **http-cache-to-mongo** will store that data in mongo db before returning you that data.

If the data for that url exists in your mongo database, **http-cache-to-mongo** returns that data, and never makes a request to that url ever again, saving your request counts against your web service api quota.

## Example
Below is an example how you would use it. If the webservice doesn't require an apiKeyName, apiKeyValue or extra params (paramsString) leave these values blank.

```

const HttpCacheToMongo = require('http-cache-to-mongo');
const apiKeyName = 'api_key';
const apiKeyValue = 'asdfwyenxcvkshgdwkssnqf0vzja';
const paramsString = '&append_to_response=credits';
const dbName = 'httpcachedb';
const collectionName = 'httpcache';
const connectionUrl = 'mongodb://localhost:27017';

const cache = new HttpCacheToMongo({
    apiKeyName,
    apiKeyValue,
    dbName,
    collectionName,
    connectionUrl,
    paramsString
});

cache.then( (cache) => {
    cache.get('https://api.mockupwebservice.local/abc/123')
    .then(json => {
        // your json data is here
    })
    .catch(error => {
        console.log(error);
    });
}).catch(error => {
    console.log(error);
});
```

---
_Source: https://npm.io/package/http-cache-to-mongo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
