2020-01-26 00:57:02 +08:00
---
2020-02-12 06:41:46 +08:00
title: Use gRPC in browser apps
2020-01-26 00:57:02 +08:00
author: jamesnk
2022-08-03 13:43:39 +08:00
description: Learn the options available to make ASP.NET Core gRPC services callable from browser apps.
2020-01-26 00:57:02 +08:00
monikerRange: '>= aspnetcore-3.0'
2024-06-18 04:11:09 +08:00
ms.author: wpickett
2022-08-05 09:39:08 +08:00
ms.date: 08/04/2022
2020-01-26 00:57:02 +08:00
uid: grpc/browser
---
2020-02-08 09:37:19 +08:00
# Use gRPC in browser apps
2020-01-26 00:57:02 +08:00
2024-08-01 00:50:11 +08:00
[!INCLUDE[ ](~/includes/not-latest-version.md )]
2020-01-26 00:57:02 +08:00
By [James Newton-King ](https://twitter.com/jamesnk )
2022-08-03 13:43:39 +08:00
It's not possible to directly call a gRPC service from a browser. gRPC uses HTTP/2 features, and no browser provides the level of control required over web requests to support a gRPC client.
2020-06-30 05:28:40 +08:00
2022-08-05 09:39:08 +08:00
gRPC on ASP.NET Core offers two browser-compatible solutions, gRPC-Web and gRPC JSON transcoding.
2020-06-30 05:28:40 +08:00
2022-08-05 09:39:08 +08:00
## gRPC-Web
2020-01-26 00:57:02 +08:00
2022-08-05 09:39:08 +08:00
gRPC-Web allows browser apps to call gRPC services with the gRPC-Web client and Protobuf.
2020-04-16 04:38:34 +08:00
2022-08-05 09:39:08 +08:00
* Similar to normal gRPC, but it has a slightly different wire-protocol, which makes it compatible with HTTP/1.1 and browsers.
* Requires the browser app to generate a gRPC client from a `.proto` file.
* Allows browser apps to benefit from the high-performance and low network usage of binary messages.
2020-04-16 04:38:34 +08:00
2022-08-05 09:39:08 +08:00
.NET has built-in support for gRPC-Web. For more information, see < xref:grpc / grpcweb > .
## gRPC JSON transcoding
gRPC JSON transcoding allows browser apps to call gRPC services as if they were RESTful APIs with JSON.
* The browser app doesn't need to generate a gRPC client or know anything about gRPC.
* RESTful APIs are automatically created from gRPC services by annotating the `.proto` file with HTTP metadata.
* Allows an app to support both gRPC and JSON web APIs without duplicating the effort of building separate services for both.
2022-09-21 20:22:05 +08:00
.NET has built-in support for creating JSON web APIs from gRPC services. For more information, see < xref:grpc / json-transcoding > .
2020-01-26 00:57:02 +08:00
2020-04-07 10:53:59 +08:00
> [!NOTE]
2022-08-03 13:43:39 +08:00
> gRPC JSON transcoding requires .NET 7 or later.
2020-09-02 19:22:39 +08:00
2020-01-26 00:57:02 +08:00
## Additional resources
2022-08-03 13:43:39 +08:00
* < xref:grpc / grpcweb >
2022-09-21 20:22:05 +08:00
* < xref:grpc / json-transcoding >