Skip to content

Instantly share code, notes, and snippets.

@lucperkins
Created October 24, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucperkins/db2898fba6cd3ed7ab82bd70153927c0 to your computer and use it in GitHub Desktop.
Save lucperkins/db2898fba6cd3ed7ab82bd70153927c0 to your computer and use it in GitHub Desktop.
const {GetTodoRequest} = require(‘./todos_pb.js’);
const {TodoServiceClient} = require(‘./todos_grpc_web_pb.js’);
const todoService = new proto.todos.TodoServiceClient(‘http://localhost:8080’);
const todoId = 1234;
var getTodoRequest = new proto.todos.GetTodoRequest();
getTodoRequest.setId(todoId);
var metadata = {};
var getTodo = todoService.getTodoById(getTodoRequest, metadata, (err, response) => {
if (err) {
console.log(err);
} else {
const todo = response.todo();
if (todo == null) {
console.log(`A TODO with the ID ${todoId} wasn’t found`);
} else {
console.log(`Fetched TODO with ID ${todoId}: ${todo.content()}`);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment