rela-json
is a Rela middleware to provide JSON-events on the Client
object.
rela-json
provides one new addition to the Server
object's prototype. Which is .select
. But first we have to load rela-json
:
var rela = require('rela'),
app = rela();
app.use(require('rela-json'));
// ...
A key to orientate your events around. (Default: "method"
)
const rela = require('rela'),
app = rela();
app.use(require('rela-json'));
app.select('do'); // Set key to listen on.
app.on('connection', function(client){
client.on('example', function(data){
console.log(data);
});
});
We can trigger the "example"
event from the client with the following JSON:
{
"do": "example",
// ...
}