Skip to content

Instantly share code, notes, and snippets.

@mohak1712
Last active April 26, 2019 15:06
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 mohak1712/a392673c1b8db46623ecb9255c547c40 to your computer and use it in GitHub Desktop.
Save mohak1712/a392673c1b8db46623ecb9255c547c40 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
const { PingPongServiceClient } = require('./ping_pong_grpc_web_pb');
const { PingRequest, PongResponse } = require('./ping_pong_pb.js');
var client = new PingPongServiceClient('http://localhost:9090', null, null);
class App extends Component {
callGrpcService = () => {
const request = new PingRequest();
request.setPing('Ping');
client.pingPong(request, {}, (err, response) => {
if (response == null) {
console.log(err)
}else {
console.log(response.getPong())
}
});
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<button style={{padding:10}} onClick={this.callGrpcService}>Click for grpc request</button>
</header>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment