Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Polytalk is a simple protocol which allows communication between different languages via TCP.
CoffeeScript JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib/Polytalk
.gitignore
LICENSE
README.md
index.js
package.json

README.md

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 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 polytalk

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.

Something went wrong with that request. Please try again.