# jsonproxy

> takes an http stream of json objects and retransmits them one by one to another destination

Latest version **1.0.1** (published 2015-04-10) · 0 weekly downloads

## Install

```sh
npm install jsonproxy
pnpm add jsonproxy
yarn add jsonproxy
bun add jsonproxy
```

Provides the command `jsonproxy`.

## 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.0.1 |
| Published | 2015-04-10 |
| First published | 2015-04-10 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Yaniv Kessler |
| Maintainers | yaniv |

## Links

- npm: https://www.npmjs.com/package/jsonproxy
- Repository: https://github.com/ironSource/json-proxy
- Issues: https://github.com/ironSource/json-proxy/issues
- npm.io page: https://npm.io/package/jsonproxy

## Dependencies (3)

- [rc](https://npm.io/package/rc.md) ~0.3.2
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [stream-slicer](https://npm.io/package/stream-slicer.md) 0.0.6

## Recent versions

- 1.0.1 (latest) — 2015-04-10

## README

# json-proxy [![Build Status](https://secure.travis-ci.org/ironSource/json-proxy.png?branch=master)](http://travis-ci.org/ironSource/json-proxy)

takes an http stream of json objects and resends them one by one to one or more destinations

## Install
```
npm install -g jsonproxy
jsonproxy --port=8080 --targets."http://localhost:7171"=10 --targets."http://localhost:7272"=10
```

## use programmatically
install locally:
```
npm install --save jsonproxy
```

expose using an http server:
```javascript
var http = require('http')
var jsonProxy = require('jsonproxy');

// will clone the default config
var config = jsonProxy.config();

// override just what we want
config.targets['http://localhost:7171'] = 10;
config.targets['http://localhost:7272'] = 10;

var proxyServer = new jsonProxy.Server(config)

var httpServer = http.createServer(function(request, response) {

    proxyServer.accept(request, function(err) {
        if (err) {
            response.statusCode = 500
        }

        response.end();
    });

});

httpServer.listen(8282, function () {
    console.log('proxy ready at http://localhost:%s', 8282)
});

```
## Config
create a file called .json-proxyrc in any of the locations specified here: [RC module](https://github.com/dominictarr/rc)
```json
{
	"port": 8181,
	"targets": {
		"http://localhost/": 10
	},
	"backoffAlgorithm": {
		"maxRetries": 10,
		"timeSlot": 1000
	}
}
```
file must pass json validation, such as [jsonlint.com](http://jsonlint.com/)

### port
the port used by the proxy to listen to incoming requests

### targets
you can specify one or more targets here in the form of "url": "concurrency level". The proxy will try its best to send requests based on the concurrency level specified for each url. If the maximum concurrency level is reached for all urls the proxy will transmit backpressure to the incoming stream (hopefully :) )

### backoffAlgorithm
In the event that an outgoing json request fails the proxy will attempt retries using an [exponential backoff algorithm](http://en.wikipedia.org/wiki/Exponential_backoff). Use maxRetries and timeSlot to control the algorithm behaviour. timeSlot is the basic unit which is used to calculate delays between attempts, it is not the exact delay used.

## Contributing
Take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). Run grunt watch while developing.

## Release History
5.1.2014 - initial release
10.4.2015 - code refresh and publish to npm

## License
Copyright (c) 2014 ironSource. Licensed under the MIT license.

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