-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient_grpc.js
56 lines (49 loc) · 1.26 KB
/
client_grpc.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const grpc = require('grpc');
const path = require('path');
const protoLoader = require('@grpc/proto-loader');
const host = 'localhost:3001';
const protoPath = `${__dirname}/../src/protos/schema.proto`;
const protoSchema = grpc.loadPackageDefinition(protoLoader.loadSync(
protoPath, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
},
)).stwno_mensa_api;
/**
* Resolve ingredient with key 1.
*/
function getIngredients() {
const client = new protoSchema.Ingredients(host, grpc.credentials.createInsecure());
const options = {
key: '1',
};
console.log('Requesting ingredients with options', options);
client.getIngredients(options, (err, res) => {
console.log('Response:', res);
if (err) {
console.error('Error', err);
}
});
}
getIngredients();
/**
* Get todays menu at university canteen.
*/
function getItems() {
const client = new protoSchema.Items(host, grpc.credentials.createInsecure());
const options = {
location: 'regensburg-university',
day: 'monday',
};
console.log('Requesting menu with options', options);
client.getItems(options, (err, res) => {
console.log('Response:', res);
if (err) {
console.error('Error', err);
}
});
}
getItems();