<commit_before># IsoProxy - General Isomorphic API Proxy with JSONRPC.

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)

## Features

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

## Install

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

## Example

Define isomorphic API:

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

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

proxy.methods.hello = function(name) {
  return new Promise(function(resolve) {
    setTimeout(function() {
      resolve("hello " + name);
    }, 100);
  });
};

proxy.ns("math").methods.add = function(a, b) {
  return a + b;
}

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());

proxy.traverse(function(urlPath, processJsonrpcRequest) {
  app.post(urlPath, function(req, res) {
    processJsonrpcRequest(req.body).then(function(jsonrpcResponse) {
      res.send(jsonrpcResponse);
    });
  });
});

app.get("/hello/:name", function(req, res) {
  proxy.api.hello(req.params.name).then(function(result) {
    res.send(result);
  });
});
```

Client side (browserify):

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

proxy.api.hello("world").then(function(result) {
  console.log(result); // => hello world
});

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

See more examples:

* [ES5, express, and browserify](examples/express/)
* [ES6, koa, and babelify](examples/koa-es6/)<commit_msg>:memo: Update README.<commit_after># 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
```

## Setup

Define isomorphic API:

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

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

proxy.methods.hello = function(name) {
  return new Promise(function(resolve) {
    setTimeout(function() {
      resolve("hello " + name);
    }, 100);
  });
};

proxy.ns("math").methods.add = function(a, b) {
  return a + b;
}

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());

proxy.traverse(function(urlPath, processJsonrpcRequest) {
  app.post(urlPath, function(req, res) {
    processJsonrpcRequest(req.body).then(function(jsonrpcResponse) {
      res.send(jsonrpcResponse);
    });
  });
});

app.get("/hello/:name", function(req, res) {
  proxy.api.hello(req.params.name).then(function(result) {
    res.send(result);
  });
});
```

Client side (browserify):

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

proxy.api.hello("world").then(function(result) {
  console.log(result); // => hello world
});

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

## Examples

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

## License

The MIT License.
{'fraction_non_alphanumeric': 0.19122556032427276, 'fraction_numerical': 0.004768717215069146, 'mean_word_length': 4.330368487928844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6899327', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1459, 'n_words': 286}