grpc / grpc/grpc-rust

Support grpc-web with JSON

Open
#2,020 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

## Feature Request

Add support for `application/grpc-web+json` which is identical to `grpc-web`, but uses the canonical JSON representation instead of protobuf.

### Crates

* `tonic-web`
* `tonic`

### Motivation

`grpc-web+json` is advantageous for browser based clients because data is serialized in a format natively understood by JavaScript (JSON). Eliminating protobuf serialization can reduce library dependency and significantly reduce package sizing while also providing performance benefits.

### Proposal

Detect `Content-Type: application/grpc-web+json` and switch to the Json codec in [`tonic-web`](https://github.com/hyperium/tonic/blob/d61a55f1ef480dad9f299012c23e199c47d99df5/tonic-web/src/call.rs#L21-L24).

### Alternatives

This may be especially difficult because, currently, supporting both `grpc` and `grpc+json` requires building twice and switching codec implementations based on headers. See https://github.com/hyperium/tonic/issues/851.

As an alternative, `tonic-web` could be updated to be agnostic of the content type and applications could switch services based on content type similar to workaround for `grpc+json`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.