polytalk

Polytalk is a simple protocol which allows communication between different languages via TCP.

npm install polytalk
1 downloads in the last week
4 downloads in the last month

Polytalk

Polytalk is a simple protocol which allows communication between different languages via TCP.

Polytalk currently supports PHP, Node.js and Ruby.

Protocol

The protocol is a simple language agnostic JSON object containing the channel, class, method and arguments. It will then return an response as either a string or JSON object.

Key Value
class The class to call the method on. Namespaced classes require the :: separator.
method The method you want to call.
arguments The arguments to inject into the method in key value pairs.

Installation

via npm:

$ npm install polyscript

Server Example

Be sure that any classes you want to be exposed by the server to the client are exposed to the the servers constructor.

JavaScript

var Polytalk = require('polytalk');

var exposes = {};
exposes['Model.Order'] = require('./model/order');

var server = new Polytalk.Server({ port: 9090, exposes: exposes });

server.run(function(connection, request) {
  server.call(request, function (response) {
    server.push(connection, response);
  });
});

Coffeescript

Polytalk = require 'polytalk'

exposes = {}
exposes['Model.Order'] = require './model/order'

server = new Polytalk.Server port: 9090, exposes: exposes

server.run (connection, request) ->
  server.call request, (response) ->
    server.push(connection, response)

Client Example

JavaScript

var Polytalk = require('polytalk');

var request = {
    class: 'Model::Order',
    method: 'findBySize',
    arguments: {
      size: 'large',
      limit: 3
    }
}

var client = new Polytalk.Client({ port: 9090 });

client.call(request, function (response) {
  console.log(response);
});

Coffeescript

Polytalk = require 'polytalk'

request = 
  class: 'Model::Order'
  method: 'findBySize'
  arguments:
    size: 'large'
    limit: 3

client = new Polytalk.Client port: 9090

client.call request, (response) ->
  console.log response

License

MIT, see LICENSE.

npm loves you