<commit_before># rpclib #

A simple library for building a JSON-RPC 2.0 compliant endpoint using Node.js.

### Usage ###

```JS
var RPCLib = require('rpclib');
```

## RPCLib Methods ##

### rpc = new RPCLib() ###

Creates a new RPC library instance. Should be done at application start up.

### rpc.addMethod(name, handler[, params][, flags]) ###
### rpc.addMethod(name, options) ###

Adds a new handler for a method name. `options` should be an object that has
`handler`, `params`, and `flags`, as keys. `handler` is a callback that is
called with (params, response) when a new request is made for this method
name. `params` is the params object sent from the client. `response` is an
instance of `RPCResponse`.

`params` should be a hash like this example:
```JS
{
    email: {type: 'string', optional: false},
    password: {type: 'string', optional: false},
    name: {type: 'string', optional: false},
    phone: {type: 'number', optional: true}
}
```
`flags` are completely optional and will be passed to your pre-processor(s).

### rpc.setPreProcessor(func) ###

Sets the pre-processor, which is called before the handler but after the request is
validated. The `func` is sent (requestObject, response, methodFlags). `requestObject`
is the request object sent from the client. `response` is an instance of `RPCResponse`.
`methodFlags` are the flags that were defined with the method.

### rpc.handleRequest(requestBody, serverResponse) ###

Handles a request from a client. `requestBody` should the body of the request made and
`serverResponse` should be an instance of `http.ServerResponse`.

## RPCResponse Methods ##

### resp.resolve(result) ###

Resolves a request with the passed `result`.

### resp.reject(errorCode[, errorMessage]) ###

Rejects a request and responds with an error object containing the passed code and message.

### resp.set(name, value) ###

Set arbitrary data on the response for later use in a post-processor, pre-processor or
handler.

### resp.get(name) ###

Get arbitrary data that was previously stored with `set`.

## Predefined Errors ##

### RPCLib.ERROR_PARSE_ERROR ###
### RPCLib.ERROR_INVALID_REQUEST ###
### RPCLib.ERROR_INVALID_METHOD ###
### RPCLib.ERROR_INVALID_PARAMS ###

## RPCClient Methods ##

### Usage ###

```JS
var RPCClient = require('rpclib').RPCCLient;
```

### client = new RPCClient([endpoint]) ###

Creates a new RPC client instance. `endpoint` should be a url.

### client.setEndpoint(endpoint) ###

`endpoint` should be a url.

### client.call(name, params, callback) ###<commit_msg>Add other exposed predefined errors to README<commit_after># rpclib #

A simple library for building a JSON-RPC 2.0 compliant endpoint using Node.js.

### Usage ###

```JS
var RPCLib = require('rpclib');
```

## RPCLib Methods ##

### rpc = new RPCLib() ###

Creates a new RPC library instance. Should be done at application start up.

### rpc.addMethod(name, handler[, params][, flags]) ###
### rpc.addMethod(name, options) ###

Adds a new handler for a method name. `options` should be an object that has
`handler`, `params`, and `flags`, as keys. `handler` is a callback that is
called with (params, response) when a new request is made for this method
name. `params` is the params object sent from the client. `response` is an
instance of `RPCResponse`.

`params` should be a hash like this example:
```JS
{
    email: {type: 'string', optional: false},
    password: {type: 'string', optional: false},
    name: {type: 'string', optional: false},
    phone: {type: 'number', optional: true}
}
```
`flags` are completely optional and will be passed to your pre-processor(s).

### rpc.setPreProcessor(func) ###

Sets the pre-processor, which is called before the handler but after the request is
validated. The `func` is sent (requestObject, response, methodFlags). `requestObject`
is the request object sent from the client. `response` is an instance of `RPCResponse`.
`methodFlags` are the flags that were defined with the method.

### rpc.handleRequest(requestBody, serverResponse) ###

Handles a request from a client. `requestBody` should the body of the request made and
`serverResponse` should be an instance of `http.ServerResponse`.

## RPCResponse Methods ##

### resp.resolve(result) ###

Resolves a request with the passed `result`.

### resp.reject(errorCode[, errorMessage]) ###

Rejects a request and responds with an error object containing the passed code and message.

### resp.set(name, value) ###

Set arbitrary data on the response for later use in a post-processor, pre-processor or
handler.

### resp.get(name) ###

Get arbitrary data that was previously stored with `set`.

## Predefined Errors ##

### RPCLib.ERROR_PARSE_ERROR ###
### RPCLib.ERROR_INVALID_REQUEST ###
### RPCLib.ERROR_INVALID_METHOD ###
### RPCLib.ERROR_INVALID_PARAMS ###
### RPCLib.ERROR_INTERNAL_ERROR ###
### RPCLib.ERROR_SERVER_ERROR ###

## RPCClient Methods ##

### Usage ###

```JS
var RPCClient = require('rpclib').RPCCLient;
```

### client = new RPCClient([endpoint]) ###

Creates a new RPC client instance. `endpoint` should be a url.

### client.setEndpoint(endpoint) ###

`endpoint` should be a url.

### client.call(name, params, callback) ###
{'fraction_non_alphanumeric': 0.13489623366641046, 'fraction_numerical': 0.0007686395080707148, 'mean_word_length': 4.7135016465422614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '549102', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1566, 'n_words': 610}