Skip to content

Instantly share code, notes, and snippets.

@kostyay
Created September 26, 2020 16:34
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 kostyay/fcf2f8573c60b68bf28dc2fdeb834190 to your computer and use it in GitHub Desktop.
Save kostyay/fcf2f8573c60b68bf28dc2fdeb834190 to your computer and use it in GitHub Desktop.
grpc-web javascript
// Import the client and the message definition
import { TimeServiceClient } from '../jsclient/time/v1/time_service_grpc_web_pb';
import { GetCurrentTimeRequest } from '../jsclient/time/v1/time_service_pb';
// Connect to the gprc-web server
const client = new TimeServiceClient("http://localhost:8080", null, null);
// This is a neat chrome extension that allows you to spy on grpc-web traffic just like you would on normal traffic.
// You can find it here: https://chrome.google.com/webstore/detail/grpc-web-developer-tools/ddamlpimmiapbcopeoifjfmoabdbfbjj?hl=en
const enableDevTools = window.__GRPCWEB_DEVTOOLS__ || (() => {});
enableDevTools([
client,
]);
// Send getCurrentTime request
client.getCurrentTime(new GetCurrentTimeRequest(), {}, (err, response) => {
// handle the response
this.lastTimeResponse = response.getCurrentTime();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment