Created
July 22, 2018 11:27
-
-
Save shobhitchittora/efbed105b01b4307b121f230890cb5e3 to your computer and use it in GitHub Desktop.
gRPC Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const grpc = require('grpc'); | |
const loader = require('@grpc/proto-loader'); | |
const bindPath = '0.0.0.0:8080'; | |
loader.load('todo.proto', { includeDirs: ['./src'] }) | |
.then((packageDefinition) => { | |
const package = grpc.loadPackageDefinition(packageDefinition); | |
const Client = package.todo_app_package.TodoApp; | |
const client = new Client(bindPath, grpc.credentials.createInsecure()); | |
client.getAll({}, function (err, res) { | |
if (err) { | |
return console.log(err); | |
} | |
console.log('todos: '); | |
return console.log(res.todos); | |
}); | |
client.getTodo({ id: 1 }, function (err, res) { | |
if (err) { | |
return console.log(err); | |
} | |
return console.log(res); | |
}); | |
client.getTodo({ id: 3 }, function (err, res) { | |
if (err) { | |
return console.log(err); | |
} | |
return console.log(res); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment