Created
September 26, 2020 16:34
-
-
Save kostyay/fcf2f8573c60b68bf28dc2fdeb834190 to your computer and use it in GitHub Desktop.
grpc-web javascript
This file contains hidden or 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
// 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