As grpc-web-client
is an implementation of a binary protocol (gRPC) in browsers that have various methods of performing HTTP requests with varying implementations across vendors limitations there are multiple underlying transports that are used to provide support across browsers.
A “transport” in this context is a wrapper of one of these methods of creating a HTTP request (e.g. fetch
or XMLHttpRequest
).
You can specify the transport that you want to use for a specific invocation through the library
property in the client
, invoke
and unary
function options.
If a transport is not specified then a transport factory is used to determine the browser’s compatible transports. See Available Transports
If none are found then an exception is thrown.
In order of attempted usage.
Uses fetch
. Requires that the browser supports Fetch with body.getReader
.
Supports binary request and response bodies and allows streaming the response without buffering it entirely, thereby safely enabling long-lived server streams.
Supported by:
- Chrome 43+
- Edge 13+
- Safari 10.1+
Uses XmlHttpRequest (XHR) with responseType = "moz-chunked-arraybuffer"
to enable reading the response stream chunks as binary as they arrive, rather than buffering the entire response as the standard XMLHttpRequest transport does, thereby safely enabling long-lived server streams.
Supported by:
- Firefox 21+
Uses XmlHttpRequest (XHR) with overrideMimeType("text/plain; charset=x-user-defined")
. overrideMimeType
allows reading the string response as individual bytes as the response arrives.
Supported by:
- Safari 6
- IE 11
This transport is not safe for long-lived or otherwise large response streams as the entire server response is maintained in memory until the request completes.
Uses http/https. This transport exists to allow usage of the grpc-web-client
library in Node.js environments such as Electron or for server-side rendering.
Supported by:
- Node.js only