Add a client example
johanbrandhorst opened this issue · 5 comments
Either using gopherjs or pure JS, just to illustrate how the MethodOverrideParam
interacts with the grpc-gateway exposed gRPC methods. Probably an example of authentication too would be nice.
@tmc @johanbrandhorst Can you please add an example client code? I cannot get my head around it. I have a "streamingCall" exposed over gRPC. How do I interact with it once I add the wsproxy?
@prince-mishra you'll need to write a websocket client. It'll depend very much on how you're talking to your server. You can look at https://github.com/johanbrandhorst/gopherjs-grpc-websocket/blob/master/client/client.go for a GopherJS example of how to use the websocket.
@johanbrandhorst Thank you so much! That helps a lot. I'll be testing it out in the browser.
@johanbrandhorst using your go client code as referrence, I was able to connect and send messages to the proxy layer. The goes like this:
var wsUri = "ws://localhost:8089/v1/bidi";
websocket = new WebSocket(wsUri);
....
websocket.send(message);
This means I need to open new websockets for every API. Is there a way to reuse the websocket on client side? Can I use the existing websocket for /v1/bidi and /api2/bidi2?
I'm afraid I don't know enough about websockets, but it appears you'll need to create a new websocket for each API endpoint. Also the connection will be closed when the bidi stream is closed so you'll need to create a new websocket every time to want to make the call.