JSTP / JavaScript Transfer Protocol
JSTP is an RPC protocol and framework which provides two-way asynchronous data
transfer with support of multiple parallel non-blocking interactions that is so
transparent that an app may not even distinguish between local async functions
and remote procedures.
And, as a nice bonus, there's a blazing fast JSON5
implementation bundled in!
This project is bound by a Code of Conduct.
Installation
JSTP works in Node.js and web browsers:
$ npm install --save @metarhia/jstp
Or, alternatively, there is
jstp.umd.js
UMD bundle.
We also have official client-side implementations for
Swift and
Java
that work effortlessly on iOS and Android 🎉
There is also an interactive CLI provided by this package:
$ npm install -g @metarhia/jstp
$ jstp-cli
Getting Started
Server:
'use strict';
const jstp = require('@metarhia/jstp');
const app = new jstp.Application('testApp', {
someService: {
sayHi(connection, name, callback) {
callback(null, `Hi, ${name}!`);
},
},
});
const server = jstp.net.createServer([app]);
server.listen(3000, () => {
console.log('TCP server listening on port 3000 🚀');
});
Client:
'use strict';
const jstp = require('@metarhia/jstp');
jstp.net.connectAndInspect(
'testApp',
null,
['someService'],
3000,
'localhost',
handleConnect
);
function handleConnect(error, connection, app) {
if (error) {
console.error(`Could not connect to the server: ${error}`);
return;
}
app.someService.sayHi('JSTP', (error, message) => {
if (error) {
console.error(`Oops, something went wrong: ${error}`);
return;
}
console.log(`Server said "${message}" 😲`);
});
}
Project Maintainers
Kudos to @tshemsedinov for the initial idea
and proof-of-concept implementation. Current project team is: