Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated lodash #1

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7e2089d
server side notifications for HTTP fixes #6
pocesar Jan 28, 2014
fb51e96
es5class lock dependency
pocesar Apr 21, 2014
37f4c77
https client
dcharbonnier May 14, 2014
a9955ee
Merge branch 'dcharbonnier-master'
pocesar May 29, 2014
4589758
bump version for release
pocesar May 29, 2014
a37cde4
add an extra to errors
dcharbonnier Jun 3, 2014
81f9606
Merge branch 'dcharbonnier-master'
pocesar Jun 3, 2014
75022ac
release 0.6.0
pocesar Jun 3, 2014
416de4b
Stringify decoded params for debug trace.
topaxi Jul 2, 2014
9de9f22
Merge pull request #12 from topaxi/stringify_params_in_trace
pocesar Jul 3, 2014
955f2fe
half way through
pocesar Jul 3, 2014
f5a437a
Merge branch 'master' of github.com:pocesar/node-jsonrpc2
pocesar Jul 3, 2014
38ac67d
fix memory leak
Aug 13, 2014
75ceaf7
simplify the previous fix
Aug 13, 2014
8dc88d1
Revert "simplify the previous fix"
Aug 14, 2014
d816c54
Revert "fix memory leak"
Aug 14, 2014
1fe3e71
don't mess up the expected behavior
Aug 14, 2014
0e70e16
Added support for OPTIONS preflight (compatibility with jquery ajax m…
FREEZX Aug 17, 2014
dd12c9f
Merge branch 'master' of github.com:FREEZX/node-jsonrpc2 into FREEZX-…
pocesar Aug 17, 2014
755c90e
preflight + ES5Class 2.x
pocesar Aug 17, 2014
577a7da
readme jsonrpc2-tools
pocesar Aug 17, 2014
975496f
Merge branch 'master' of github.com:trademob/node-jsonrpc2 into trade…
pocesar Aug 19, 2014
468fc7b
Merge branch 'trademob-master'
pocesar Aug 19, 2014
99e19e4
0.8.0 closes #13
pocesar Aug 19, 2014
e6342f2
fix example ES5class 2.x
pocesar Aug 19, 2014
629e08f
updated README.md
utvara Aug 19, 2014
a4fa554
Merge pull request #15 from trademob/master
pocesar Aug 20, 2014
81e18fc
set package.json versions
pocesar Aug 20, 2014
3061d08
Merge branch 'master' of github.com:pocesar/node-jsonrpc2
pocesar Aug 20, 2014
12282f3
README.md
pocesar Aug 20, 2014
3a1acc6
Merge branch 'master' of github.com:pocesar/node-jsonrpc2
pocesar Aug 20, 2014
486fff7
allow ids as string types
bencxr Feb 18, 2015
6b07599
address null case
bencxr Feb 18, 2015
3fdcfaf
Allows to send 0/false values as a result
May 3, 2015
429d083
Removes semicolon
May 3, 2015
efb6c03
id as number / string / null
pocesar May 4, 2015
1440532
Merge branch 'bencxr-allowStringIds'
pocesar May 4, 2015
8aeee18
Merge branch 'OhDavit-fix/allow_returning_0_false'
pocesar May 4, 2015
416e764
1.0.0
pocesar May 4, 2015
c320031
updated inheritance from eventemitter3
pocesar May 4, 2015
143a8be
add breaking change notice
pocesar May 4, 2015
a0aa31c
bump
pocesar May 4, 2015
dc64d08
test
pocesar Sep 12, 2015
4c0d490
fixes #22
pocesar Sep 13, 2015
a651419
update dependencies
pocesar Apr 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"devel" : true,
"node" : true,
"sub" : true,
"esversion": 6,
"quotmark": "single"
}
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"reporter": "list",
"ui": "exports",
"check-leaks": true
}
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.8"
- "node"
- "lts/*"
- "10"
327 changes: 170 additions & 157 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,157 +1,170 @@
[![Build Status](https://travis-ci.org/pocesar/node-jsonrpc2.png?branch=master)](https://travis-ci.org/pocesar/node-jsonrpc2)

[![NPM](https://nodei.co/npm/json-rpc2.png?downloads=true)](https://nodei.co/npm/json-rpc2/)

# node-jsonrpc2

JSON-RPC 2.0 server and client library, with `HTTP` (with `Websocket` support) and `TCP` endpoints

This fork is a rewrite with proper testing framework, linted code, compatible with node 0.8.x and 0.10.x, class inheritance, and added functionalities

## Install

To install node-jsonrpc2 in the current directory, run:

```bash
npm install json-rpc2 --save
```

## Usage

Firing up an efficient JSON-RPC server becomes extremely simple:

```js
var rpc = require('json-rpc2');

var server = rpc.Server.create({
'websocket': true // is true by default
'headers': { // allow custom headers is empty by default
'Access-Control-Allow-Origin': '*'
}
});

function add(args, opt, callback) {
callback(null, args[0] + args[1]);
}

server.expose('add', add);

// you can expose an entire object as well:

server.expose('namespace', {
'function1': function(){},
'function2': function(){},
'function3': function(){}
});
// expects calls to be namespace.function1, namespace.function2 and namespace.function3

// listen creates an HTTP server on localhost only
server.listen(8000, 'localhost');
```

And creating a client to speak to that server is easy too:

```js
var rpc = require('json-rpc2');

var client = rpc.Client.create(8000, 'localhost');

// Call add function on the server

client.call('add', [1, 2], function(err, result) {
console.log('1 + 2 = ' + result);
});
```

Create a raw (socket) server using:

```js
var rpc = require('json-rpc2');

var server = rpc.Server.create();

// non-standard auth for RPC, when using this module using both client and server, works out-of-the-box
server.enableAuth('user', 'pass');

// Listen on socket
server.listenRaw(8080, 'localhost');
```

## Extend, overwrite, overload

Any class can be extended, or used as a mixin for new classes, since it uses [ES5Class](http://github.com/pocesar/ES5-Class) module.

For example, you may extend the `Endpoint` class, that automatically extends `Client` and `Server` classes.
Extending `Connection` automatically extends `SocketConnection` and `HttpServerConnection`.

```js
var rpc = require('json-rpc2');

rpc.Endpoint.include({
'newFunction': function(){

}
});

var
server = rpc.Server.create(),
client = rpc.Client.create();

server.newFunction(); // already available
client.newFunction(); // already available
```

To implement a new class method (that can be called without an instance, like `rpc.Endpoint.newFunction`:

```js
var rpc = require('json-rpc2');

rpc.Endpoint.implement({
'newFunction': function(){
}
});

rpc.Endpoint.newFunction(); // available
rpc.Client.newFunction(); // every
rpc.Server.newFunction(); // where
```

Don't forget, when you are overloading an existing function, you can call the original function using `$super`

```js
var rpc = require('json-rpc2');

rpc.Endpoint.implement({
'trace': function(direction, message){
this.$super(' (' + direction + ')', message); //call the last defined function
}
});
```

And you can start your classes directly from any of the classes

```js
var MyCoolServer = require('json-rpc2').Server.define('MyCoolServer', {
myOwnFunction: function(){
},
}, {
myOwnClassMethod: function(){
}
}); // MyCoolServer will contain all class and instance functions from Server

MyCoolServer.myOwnClassMethod(); // class function
MyCoolServer.create().myOwnFunction(); // instance function
```

## Debugging

This module uses the [debug](http://github.com/visionmedia/debug) package, to debug it, you need to set the Node
environment variable to jsonrpc, by setting it in command line as `set DEBUG=jsonrpc` or `export DEBUG=jsonrpc`

## Examples

To learn more, see the `examples` directory, peruse `test/jsonrpc-test.js`, or
simply "Use The Source, Luke".

More documentation and development is on its way.

[![Build Status](https://travis-ci.org/pocesar/node-jsonrpc2.svg?branch=master)](https://travis-ci.org/pocesar/node-jsonrpc2)

[![NPM](https://nodei.co/npm/json-rpc2.svg?downloads=true)](https://nodei.co/npm/json-rpc2/)

# node-jsonrpc2

JSON-RPC 2.0 server and client library, with `HTTP` (with `Websocket` support) and `TCP` endpoints

This fork is a rewrite with proper testing framework, linted code, compatible with node 0.8.x and 0.10.x, class inheritance, and added functionalities

## Tools

Check [jsonrpc2-tools](https://www.npmjs.org/package/jsonrpc2-tools) for some nice additions to this module.

## Install

To install node-jsonrpc2 in the current directory, run:

```bash
npm install json-rpc2 --save
```

## Changes from 1.x

* Uses native EventEmitter instead of EventEmitter3

## Changes from 0.x

* Before, the `id` member was permissive and wouldn't actually adhere to the RFC, allowing anything besides `undefined`.
* If your application relied on weird id constructs other than `String`, `Number` or `null`, it might break if you update to 1.x

## Usage

Firing up an efficient JSON-RPC server becomes extremely simple:

```js
var rpc = require('json-rpc2');

var server = rpc.Server.$create({
'websocket': true, // is true by default
'headers': { // allow custom headers is empty by default
'Access-Control-Allow-Origin': '*'
}
});

function add(args, opt, callback) {
callback(null, args[0] + args[1]);
}

server.expose('add', add);

// you can expose an entire object as well:

server.expose('namespace', {
'function1': function(){},
'function2': function(){},
'function3': function(){}
});
// expects calls to be namespace.function1, namespace.function2 and namespace.function3

// listen creates an HTTP server on localhost only
server.listen(8000, 'localhost');
```

And creating a client to speak to that server is easy too:

```js
var rpc = require('json-rpc2');

var client = rpc.Client.$create(8000, 'localhost');

// Call add function on the server

client.call('add', [1, 2], function(err, result) {
console.log('1 + 2 = ' + result);
});
```

Create a raw (socket) server using:

```js
var rpc = require('json-rpc2');

var server = rpc.Server.$create();

// non-standard auth for RPC, when using this module using both client and server, works out-of-the-box
server.enableAuth('user', 'pass');

// Listen on socket
server.listenRaw(8080, 'localhost');
```

## Extend, overwrite, overload

Any class can be extended, or used as a mixin for new classes, since it uses [ES5Class](http://github.com/pocesar/ES5-Class) module.

For example, you may extend the `Endpoint` class, that automatically extends `Client` and `Server` classes.
Extending `Connection` automatically extends `SocketConnection` and `HttpServerConnection`.

```js
var rpc = require('json-rpc2');

rpc.Endpoint.$include({
'newFunction': function(){

}
});

var
server = rpc.Server.$create(),
client = rpc.Client.$create();

server.newFunction(); // already available
client.newFunction(); // already available
```

To implement a new class method (that can be called without an instance, like `rpc.Endpoint.newFunction`):

```js
var rpc = require('json-rpc2');

rpc.Endpoint.$implement({
'newFunction': function(){
}
});

rpc.Endpoint.newFunction(); // available
rpc.Client.newFunction(); // every
rpc.Server.newFunction(); // where
```

Don't forget, when you are overloading an existing function, you can call the original function using `$super`

```js
var rpc = require('json-rpc2');

rpc.Endpoint.$implement({
'trace': function($super, direction, message){
$super(' (' + direction + ')', message); //call the last defined function
}
});
```

And you can start your classes directly from any of the classes

```js
var MyCoolServer = require('json-rpc2').Server.$define('MyCoolServer', {
myOwnFunction: function(){
},
}, {
myOwnClassMethod: function(){
}
}); // MyCoolServer will contain all class and instance functions from Server

MyCoolServer.myOwnClassMethod(); // class function
MyCoolServer.$create().myOwnFunction(); // instance function
```

## Debugging

This module uses the [debug](http://github.com/visionmedia/debug) package, to debug it, you need to set the Node
environment variable to jsonrpc, by setting it in command line as `set DEBUG=jsonrpc` or `export DEBUG=jsonrpc`

## Examples

To learn more, see the `examples` directory, peruse `test/jsonrpc-test.js`, or
simply "Use The Source, Luke".

More documentation and development is on its way.

6 changes: 3 additions & 3 deletions examples/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var
/*
Connect to HTTP server
*/
var client = rpc.Client.create(8088, 'localhost', 'myuser', 'secret123');
var client = rpc.Client.$create(8088, 'localhost', 'myuser', 'secret123');

client.call('add', [1, 2], function (err, result){
if (err) {
Expand All @@ -31,7 +31,7 @@ client.call('delayed.echo', ['Echo.', 1500], function (err, result){
/*
Connect to Raw socket server
*/
var socketClient = rpc.Client.create(8089, 'localhost', 'myuser', 'secret123');
var socketClient = rpc.Client.$create(8089, 'localhost', 'myuser', 'secret123');

socketClient.connectSocket(function (err, conn){
if (err) {
Expand Down Expand Up @@ -67,7 +67,7 @@ socketClient.connectSocket(function (err, conn){
/*
Connect to Websocket server
*/
var WebsocketClient = rpc.Client.create(8088, 'localhost', 'myuser', 'secret123');
var WebsocketClient = rpc.Client.$create(8088, 'localhost', 'myuser', 'secret123');

WebsocketClient.connectWebsocket(function (err, conn){
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var rpc = require('../src/jsonrpc');

var server = rpc.Server.create({
var server = rpc.Server.$create({
websocket: true
});

Expand Down
Loading