gRPC-Web is going GA
原文: https://www.cncf.io/blog/2018/10/24/grpc-web-is-going-ga
On behalf of the Cloud Native Computing Foundation, I’m excited to announce the GA release of gRPC-Web, a JavaScript client library that enables web apps to communicate directly with backend gRPC services, without requiring an HTTP server to act as an intermediary. This means that you now easily build truly end-to-end gRPC application architectures by defining your client- and server-side data types and service interfaces using .proto files. gRPC-Web thus provides a compelling new alternative to the entire REST paradigm of web development.
The basics
gRPC-Web enables you to define the service “contract” between client web applications and backend gRPC servers using .protodefinitions and auto-generate client JavaScript (you can choose between Closure compiler JavaScript or the more widely used CommonJS). What you get to leave out of the development process: creating custom JSON serialization and deserialization logic, wrangling HTTP status codes (which can vary across REST APIs), content type negotiation, etc.
From a broader architectural perspective, what gRPC-Web makes possible is end-to-end gRPC. The diagram below illustrates this:

In the gRPC-Web universe on the left, a client application speaks Protocol Buffers to a gRPC backend server that speaks Protocol Buffers to other gRPC backend services. In the REST universe on the right, the web app speaks HTTP to a backend REST API server that then speaks Protocol Buffers to backend services.
To be clear, there’s nothing wrong with the REST application on the right per se. Tons of highly successful applications have been built using REST API servers that communicate with backend services using non-HTTP protocols. But imagine those applications’ development processes united around a single protocol and a single set of .proto interfaces (and thus a single set of service contracts) and you can almost feel the countless hours saved and headaches avoided. The benefits of gRPC-Web aren’t “merely” technological; they’re organizational as well. That bright orange line isn’t just a different protocol—it’s an independent source of work and cognitive load that you can now easily turn bright green.
Advantages of using gRPC-Web
gRPC-Web will offer an ever-broader feature set over time. But I can see it offering a handful of big wins from the get-go:
- End-to-end gRPC — As mentioned above, with gRPC-Web you can officially cut the REST component out of your stack and replace it with pure gRPC, enabling you to craft your entire RPC pipeline using Protocol Buffers. Imagine a scenario in which a client request goes to an HTTP server, which then interacts with 5 backend gRPC services. There’s a good chance that you’ll spend as much time building the HTTP interaction layer as you will building the entire rest of the pipeline.
- Tighter coordination between frontend and backend teams — Think back to the diagram up above. With the entire RPC pipeline defined using Protocol Buffers, you no longer need to have your “microservices teams” alongside your “client team.” The client-backend interaction is just one more gRPC layer amongst others. I honestly have yet to fully grasp the implications for end-to-end testing, service mesh integration, continuous integration/delivery, and more.
- Easily generate client libraries — With gRPC-Web, the server that interacts with the “outside” world, i.e. the membrane connecting your backend stack to the internet, is now a gRPC server instead of an HTTP server, that means that all of your service’s client libraries can be gRPC libraries. Need client libraries for Ruby, Python, Java, and 4 other languages? You no longer need to write HTTP clients for all of them.
A gRPC-Web example
The previous section illustrated some of the high-level advantages of gRPC-Web for large-scale applications. Now let’s get closer to the metal with an example: a simple TODO app. In gRPC-Web you can start with a simple todos.proto definition like this:
| syntax = “proto3”; | |
| package todos; | |
| message Todo { | |
| string content = 1; | |
| bool finished = 2; | |
| } | |
| message GetTodoRequest { | |
| int32 id = 1; | |
| } | |
| service TodoService { | |
| rpc GetTodoById (GetTodoRequest) returns (Todo); | |
| } |
You can use that .proto definition to generate CommonJS client-side code using the protoc command-line tool:
| protoc echo.proto \ | |
| --js_out=import_style=commonjs:./output \ | |
| --grpc-web_out=import_style=commonjs:./output |
Now fetching a list of TODOs from a backend gRPC server can be as simple as this:
| const {GetTodoRequest} = require(‘./todos_pb.js’); | |
| const {TodoServiceClient} = require(‘./todos_grpc_web_pb.js’); | |
| const todoService = new proto.todos.TodoServiceClient(‘http://localhost:8080’); | |
| const todoId = 1234; | |
| var getTodoRequest = new proto.todos.GetTodoRequest(); | |
| getTodoRequest.setId(todoId); | |
| var metadata = {}; | |
| var getTodo = todoService.getTodoById(getTodoRequest, metadata, (err, response) => { | |
| if (err) { | |
| console.log(err); | |
| } else { | |
| const todo = response.todo(); | |
| if (todo == null) { | |
| console.log(`A TODO with the ID ${todoId} wasn’t found`); | |
| } else { | |
| console.log(`Fetched TODO with ID ${todoId}: ${todo.content()}`); | |
| } | |
| } | |
| }); |
Again, no HTTP codes or methods, no JSON parsing, no header negotiation. You declare data types and a service interface and gRPC-Web abstracts away all the “hard wiring” boilerplate, leaving you with a clean and human-friendly API (essentially the same API as the current Node.js for gRPC API, just transferred to the client).
On the backend, the gRPC server can be written in any language that supports gRPC, including Go, Java, C++, Ruby, Node.js, and many others (see language-specific docs in the official gRPC docs). The last piece of the puzzle is the service proxy. From the get-go, gRPC-Web will support Envoy as the default service proxy, which has a built-in envoy.grpc_web filter that you can apply with just a few lines of copy-and-pastable configuration. I’ll be saying more about this on the Envoy blog soon.
Next steps
Going GA means that the core building blocks are firmly in place and ready for usage in production web applications. But there’s still much more to come for gRPC-Web. Check out the official roadmap to see what the core team envisions for the near future.
If you’re interested in contributing to gRPC-Web, there are a few things that the core team would love community help with:
- Front-end framework integration — Commonly used front-end frameworks like React, Angular, and Vue don’t yet offer official support for gRPC-Web. But we would love to see these frameworks support it, as each of them would greatly benefit from gRPC.
- Language-specific proxy support — As of the GA release, Envoy is the default proxy for gRPC-Web, offering support via a special module. But we’d also love to see development of in-process proxies for specific languages. In-process proxies obviate the need for special proxies—such as Envoy and nginx—and would make using gRPC-Web even easier.
We’d also love to get feature requests from the community. Currently the best way to make feature requests is to fill out the gRPC-Web roadmap features survey. Just list features you’d like to see and also let us know if you’d like to contributing to those features’ development in the I’d like to contribute to section. The gRPC-Web engineers will be sure to take that information to heart over the course of the project’s development.
gRPC-Web is going GA的更多相关文章
- Blazor WebAssembly + Grpc Web = 未来?
Blazor WebAssembly是什么 首先来说说WebAssembly是什么,WebAssembly是一个可以使C#,Java,Golang等静态强类型编程语言,运行在浏览器中的标准,浏览器厂商 ...
- 进行API开发选gRPC还是HTTP APIs?
上一篇文章我带着大家体验了一把<ASP.NET Core 3.0 上的gRPC服务模板初体验(多图)>,如果有兴趣的可以点击链接进行查看,相信跟着做的你,也是可以跑起来的.这篇文章我们将一 ...
- net core 3.0 之Grpc新特性小试牛刀
相信微服务大家伙都有听说和知道,好处弊端咱也不多说了,Grpc算是一个比较全面的微服务框架,也得到微软的支持 总结下来就是,跨平台,可靠,通信快,扩展性强,网络消耗小,模板多语言通用 光说好处,没 ...
- [系列] Go gRPC 调试工具
目录 概述 写一个 gRPC API grpcui 使用 go-gin-api 系列文章 概述 最近这段时间工作挺忙的,发现已经 3 周没更文了... 感谢你们还在,今天给大家分享一款 gRPC 的调 ...
- Go gRPC 调试工具
概述 最近这段时间工作挺忙的,发现已经 3 周没更文了... 感谢你们还在,今天给大家分享一款 gRPC 的调试工具. 进入正题. 当我们在写 HTTP 接口的时候,使用的是 Postman 进行接口 ...
- 一个新实验:使用gRPC-Web从浏览器调用.NET gRPC服务
今天给大家翻译一篇由ASP.NET首席开发工程师James Newton-King前几天发表的一篇博客,文中带来了一个实验性的产品gRPC-Web.大家可以点击文末的讨论帖进行相关反馈.我会在文章末尾 ...
- grpc调试工具
grpcurl 和 grpcui 都是调试grpc的利器,前者用于命令行,类似curl工具:后者是以web的形式进行调试的,类似postman工具. 有了这两款工具,我们不用写任何客户端代码,也能方便 ...
- 旧 WCF 项目成功迁移到 asp.net core web api
背景 接上一篇,放弃了 asp.net core + gRPC 的方案后,我灵光一闪,为什么不用 web api 呢?不也是 asp.net core 的吗?虽然 RESTful 不是强约束,客户端写 ...
- Golang gRPC调试工具
目录 Golang gRPC调试工具 1. 命令行工具 grpcurl 1.1 安装 1.2 验证 1.3 注册反射 1.4 使用示例 2. web调试工具grpcui 2.1 安装 2.2 验证 2 ...
- 如何基于gRPC沟通微服务框架
本文我们来讲解一下如何使用 gRPC构建微服务,gRPC是一个开源框架,可用于构建可扩展且高性能的微服务并创建服务之间的通信. 背景 随着企业越来越多地转向微服务,对构建这些微服务的低延迟和可扩展框架 ...
随机推荐
- 20170814xlVBA部分代号收盘价转置
原始数据: 转置效果: Sub TransformData() Dim Rng As Range Dim Arr As Variant Dim Dic As Object Dim dCode As O ...
- Ubuntu 18.04 install JDK8.201
sudo add-apt-repository ppa:webupd8team/java Press Enter to continue. sudo apt update sudo apt insta ...
- 附录A——面向对象基础
在学习设计模式之前,C#语言中一些基本的面向对象的知识还是应该具备的,比如像继承.多态,接口.抽象类,集合.泛型等. A.2 类与实例 什么是对象? 一切事物(事和物)都是对象,对象就是可以看到.感觉 ...
- 修改MAC地址的方法(未测试)
用ioctl控制,通过SIOCGIFHWADDR获取MAC地址,SIOCSIFHWADDR设置MAC地址,不过在设 置MAC地址之前,要先把网卡down掉,设置好了以后,再UP起来. #include ...
- spring boot 学习(十一)使用@Async实现异步调用
使用@Async实现异步调用 什么是”异步调用”与”同步调用” “同步调用”就是程序按照一定的顺序依次执行,,每一行程序代码必须等上一行代码执行完毕才能执行:”异步调用”则是只要上一行代码执行,无需等 ...
- POJ 3220 位运算+搜索
转载自:http://blog.csdn.net/lyhypacm/article/details/5813634 DES:相邻的两盏灯状态可以互换,给出初始状态.询问是否能在三步之内到达.如果能的话 ...
- 7dynamic_cast用法
已知下面的class层次,其中每一个class都定义有一个default constructor和一个virtual destructor: class X{……}; class A{……}; cla ...
- [转载]oracle位图索引
原文URL: http://lzfhope.blog.163.com/blog/static/63639922013119112011947/ 很详细,推荐看5遍
- MySQL 5.7 分区表性能下降的案例分析
转载自:https://mp.weixin.qq.com/s/K3RpSBAIWFwGCIWyfF0QPA 前言:希望通过本文,使MySQL5.7.18的使用者知晓分区表使用中存在的陷阱,避免在该版本 ...
- Saiku_学习_01_saiku安装与运行
一.下载saiku 1.下载地址 官网:https://community.meteorite.bi/ 2.解压后文件结构 3.ROOT和saiku 在tomcat/webapp 下有两个web应用, ...