# isoproxy

> General isomorphic API proxy with JSONRPC.

Latest version **0.2.1** (published 2015-05-27) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2015-05-27 |
| First published | 2015-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.11.x |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shintaro Seki |
| Maintainers | s-shin |
| Keywords | isomorphic, koa |

## Links

- npm: https://www.npmjs.com/package/isoproxy
- Repository: https://github.com/s-shin/isoproxy
- Issues: https://github.com/s-shin/isoproxy/issues
- npm.io page: https://npm.io/package/isoproxy

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^3.9.2
- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) ^0.8.1
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^5.4.3

## Recent versions

- 0.2.1 (latest) — 2015-05-27
- 0.2.0 — 2015-05-27
- 0.1.3 — 2015-05-22
- 0.1.2 — 2015-05-22
- 0.1.1 — 2015-05-21
- 0.1.0 — 2015-05-21

## README

# IsoProxy - General Isomorphic API Proxy

IsoProxy is a simple proxy inspired [Fetchr](https://github.com/yahoo/fetchr),
and the motivation is the same as in Fetchr.

[![Build Status](https://travis-ci.org/s-shin/isoproxy.svg)](https://travis-ci.org/s-shin/isoproxy)
[![npm version](https://badge.fury.io/js/isoproxy.svg)](http://badge.fury.io/js/isoproxy)
[![Dependency Status](https://david-dm.org/s-shin/isoproxy.svg)](https://david-dm.org/s-shin/isoproxy)
[![devDependency Status](https://david-dm.org/s-shin/isoproxy/dev-status.svg)](https://david-dm.org/s-shin/isoproxy#info=devDependencies)
[![license](https://img.shields.io/github/license/s-shin/isoproxy.svg)](https://github.com/s-shin/isoproxy/blob/master/LICENSE)

## Features

* Isolation from a web application framework by adopting JSONRPC.
* ES6 friendly with Promise.

## Install

```sh
npm install isoproxy --save
```

## Usage

Define isomorphic API:

```js
// proxy.js
var IsoProxy = require("isoproxy");

var proxy = new IsoProxy({
  root: "/api",
  isServer: (typeof window === "undefined")
});

proxy.setInterfaces({
  math: ["add", "sub"]
});

proxy.setImplementations({
  math: {
    add: function(x, y) { return x + y; },
    sub: function(x, y) { return x - y; }
  }
});

module.exports = proxy;
```

Server side (express):

```js
// server.js
var express = require("express");
var bodyParser = require("body-parser");
var proxy = require("./proxy");

var app = express();
app.use(bodyParser.json());

Object.keys(proxy.routes).forEach(function(urlPath) {
  var processJsonrpcRequest = proxy.routes[urlPath];
  app.post(urlPath, function(req, res) {
    processJsonrpcRequest(req.body).then(function(jsonrpcResponse) {
      res.send(jsonrpcResponse);
    });
  });
});

app.get("/add/:x/:y", function(req, res) {
  proxy.api.math.add(+req.params.x, +req.params.y)
    .then(function(result) {
      res.send(""+result);
    });
});
```

Client side (browserify):

```js
// client.js
var proxy = require("./proxy");

proxy.api.math.add(1, 2).then(function(r) {
  console.log(r); // => 3
});

proxy.api.math.sub(1, 2).then(function(r) {
  console.log(r); // => -1
});
```

## Why interfaces and implementations are separated?

It is because the client side need not know implementation details.
In other words, implementations can be hidden from users.

Please see [this example](example/koa-es6) for more information.

## Examples

* [ES5, express, and browserify](examples/express/)
* [ES6, koa, and babelify](examples/koa-es6/)

## Links

* [koa-isoproxy](https://github.com/s-shin/koa-isoproxy)
  * koa middleware for IsoProxy.

## Supported Browsers

Above Internet Explorer 9 and other modern browsers.

## License

The MIT License.

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