diff --git a/aspnetcore/grpc/browser.md b/aspnetcore/grpc/browser.md index e8ef17f0e3..2adc707fdd 100644 --- a/aspnetcore/grpc/browser.md +++ b/aspnetcore/grpc/browser.md @@ -4,7 +4,7 @@ author: jamesnk description: Learn how to configure gRPC services on ASP.NET Core to be callable from browser apps using gRPC-Web. monikerRange: '>= aspnetcore-3.0' ms.author: jamesnk -ms.date: 02/16/2020 +ms.date: 04/15/2020 uid: grpc/browser --- # Use gRPC in browser apps @@ -23,6 +23,15 @@ By [James Newton-King](https://twitter.com/jamesnk) It is not possible to call a HTTP/2 gRPC service from a browser-based app. [gRPC-Web](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-WEB.md) is a protocol that allows browser JavaScript and Blazor apps to call gRPC services. This article explains how to use gRPC-Web in .NET Core. +## gRPC-Web in ASP.NET Core vs. Envoy + +There are two choices for how to add gRPC-Web to an ASP.NET Core app: + +* Support gRPC-Web alongside gRPC HTTP/2 in ASP.NET Core. This option uses middleware provided by the `Grpc.AspNetCore.Web` package. +* Use the [Envoy proxy's](https://www.envoyproxy.io/) gRPC-Web support to translate gRPC-Web to gRPC HTTP/2. The translated call is then forwarded onto the ASP.NET Core app. + +There are pros and cons to each approach. If you're already using Envoy as a proxy in your app's environment, it might make sense to also use it to provide gRPC-Web support. If you want a simple solution for gRPC-Web that only requires ASP.NET Core, `Grpc.AspNetCore.Web` is a good choice. + ## Configure gRPC-Web in ASP.NET Core gRPC services hosted in ASP.NET Core can be configured to support gRPC-Web alongside HTTP/2 gRPC. gRPC-Web does not require any changes to services. The only modification is startup configuration. @@ -94,7 +103,7 @@ The preceding code: The `GrpcWebHandler` has the following configuration options when created: * **InnerHandler**: The underlying that makes the gRPC HTTP request, for example, `HttpClientHandler`. -* **Mode**: An enumeration type that specifies whether the gRPC HTTP request request `Content-Type` is `application/grpc-web` or `application/grpc-web-text`. +* **Mode**: An enumeration type that specifies whether the gRPC HTTP request `Content-Type` is `application/grpc-web` or `application/grpc-web-text`. * `GrpcWebMode.GrpcWeb` configures content to be sent without encoding. Default value. * `GrpcWebMode.GrpcWebText` configures content to be base64 encoded. Required for server streaming calls in browsers. * **HttpVersion**: HTTP protocol `Version` used to set [HttpRequestMessage.Version](xref:System.Net.Http.HttpRequestMessage.Version) on the underlying gRPC HTTP request. gRPC-Web doesn't require a specific version and doesn't override the default unless specified.