Experimental: Add grpc-web HTTP client #2174
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This client is only enabled when gRPC-Go is built with GOARCH=WASM and GOOS=js. It is a spec-compliant gRPC-Web client.
I have been experimenting with a gRPC-web client written with Go and WASM, which culminated in https://github.com/johanbrandhorst/grpc-wasm, but I thought I could do one better. The idea is to have a program that works both when compiled normally and when compiled to WASM. This client is HTTP based and uses the WASM specific Fetch API based
http.RoundTripper
added in golang/go#25550.I realise this will probably never be merged, but it's been a fun experiment, and in my testing both unary and server side streaming requests work. I've created a repo for testing this which can be found here: https://github.com/johanbrandhorst/wasm-experiments/tree/master/grpc. The demo showcases 2 unary request responses and 1 server streaming request response stream. It shows the successful parsing of gRPC status errors.
I mentioned this experiment to @jadekler on the Gophers Slack, and also this could probably be implemented much easier if #2112 was fixed.