<commit_before>This is a JSON-RPC v2 handler middleware for the Express library on [node.js](http://nodejs.org).

First, simply include node-express-JSON-RPC2 in your configure/use statements before app.router:

    var express = require('express'),
    	jsonrpc = require('node-express-JSON-RPC2');

    app.configure(function(){
    	...
    	app.use( express.jsonrpc() );
    	...
    	app.use( app.router );
    });

Then wihin a route, use res.rpc to handle a given method. Unless the request is a notification, a response
function will be passed in after the parameters to handle the response.

    app.post('/path/for/rpc/calls', function (req, res, next) {
    	// notification (no response expected)
    	res.rpc('notification_method', function (params) {
    		// do processing here
    	});
    
    	// non-notification (response expected)
    	res.rpc('method_name', function (params, respond) {
    		// do processing here
    
    		// if everything is OK return result object:
    		respond( { result: resultData } );
    
    		// if something is wrong, return an error code:
    		respond(jsonrpc.INVALID_PARAMS)
    		// OR an extended error object:
    		respond({
    			error: {
    				code: jsonrpc.INVALID_PARAMS,
    				message: 'You gave me invalid parameters!',
    				data: data
    			}
    		});
    	});
    });

The middleware provides standard error codes and messages defined by the [JSON-RPC version 2 spec](http://www.jsonrpc.org/specification)

You can reference error codes by static string. For example, you may:

    respond(jsonRPC.INVALID_REQUEST);

And your response will be converted to:

    {
    	error: {
    		code: -32600,
    		message: 'Invalid request'
    	}
    }

The error code constants for reference:

    Variable Name    Code     Message
    ------------------------------------------------
    PARSE_ERROR      -32700  'Parse error'
    INVALID_REQUEST  -32600  'Invalid request'
    METHOD_NOT_FOUND -32601  'Method not found'
    INVALID_PARAMS   -32602  'Invalid parameters'
    INTERNAL_ERROR   -32603  'Internal error'


**Note** For strict adherence to the specification, you cannot use bodyParser in conjuction with node-express-JSON-RPC2 because bodyParser will catch invalid JSON and return early, preventing a "Parse error" RPC response. If you are not terribly worried about strict compliance, using bodyParser is fine.<commit_msg>README.md cleanup<commit_after>This is a JSON-RPC v2 handler middleware for the Express library on [node.js](http://nodejs.org).

First, simply include node-express-JSON-RPC2 in your configure/use statements before app.router:

    var express = require('express'),
    	jsonrpc = require('node-express-JSON-RPC2');

    app.configure(function(){
    	...
    	app.use( express.jsonrpc() );
    	...
    	app.use( app.router );
    });

Then wihin a route, use res.rpc to handle a given method. Unless the request is a notification, a response
function will be passed in after the parameters to handle the response.

    app.post('/path/for/rpc/calls', function (req, res, next) {
    	// notification (no response expected)
    	res.rpc('notification_method', function (params) {
    		// do processing here
    	});
    
    	// non-notification (response expected)
    	res.rpc('method_name', function (params, respond) {
    		// do processing here
    
    		// if everything is OK return result object:
    		respond( { result: resultData } );
    
    		// if something is wrong, return an error code:
    		respond(jsonrpc.INVALID_PARAMS)
    		// OR an extended error object:
    		respond({
    			error: {
    				code: jsonrpc.INVALID_PARAMS,
    				message: 'You gave me invalid parameters!',
    				data: data
    			}
    		});
    	});
    });

The middleware provides standard error codes and messages defined by the [JSON-RPC version 2 spec](http://www.jsonrpc.org/specification)

You can reference error codes by static string. For example, you may:

    respond(jsonRPC.INVALID_REQUEST);

And your response will be converted to:

    {
    	error: {
    		code: -32600,
    		message: 'Invalid request'
    	}
    }

The error code constants for reference:

    Variable Name    Code     Message
    ------------------------------------------------
    PARSE_ERROR      -32700  'Parse error'
    INVALID_REQUEST  -32600  'Invalid request'
    METHOD_NOT_FOUND -32601  'Method not found'
    INVALID_PARAMS   -32602  'Invalid parameters'
    INTERNAL_ERROR   -32603  'Internal error'


**Note:** For strict adherence to the specification, you cannot use bodyParser in conjuction with node-express-JSON-RPC2 because bodyParser will catch invalid JSON and return early, preventing a "Parse error" RPC response. If you are not terribly worried about strict compliance, using bodyParser is fine.
{'fraction_non_alphanumeric': 0.10998132392612575, 'fraction_numerical': 0.014525835235526042, 'mean_word_length': 2.594332587621178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2783447', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1361, 'n_words': 482}