-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathclient.js
More file actions
28 lines (23 loc) · 693 Bytes
/
client.js
File metadata and controls
28 lines (23 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const jaysonBrowserClient = require('jayson/lib/client/browser');
const fetch = require('node-fetch');
const callServer = function(request, callback) {
const options = {
method: 'POST',
body: request,
headers: {
'Content-Type': 'application/json',
}
};
fetch('http://localhost:3000', options)
.then(function(res) { return res.text(); })
.then(function(text) { callback(null, text); })
.catch(function(err) { callback(err); });
};
const client = new jaysonBrowserClient(callServer, {
// other options go here
});
client.request('multiply', [5, 5], function(err, error, result) {
if(err) throw err;
console.log(result); // 25
});