gRPC-Web publishing, REST is blown away again?

Cloud computing native Foundation (CNCF) officially released the GA version of gRPC-Web, which is a JavaScript client library that allows Web applications to communicate directly with the back-end gRPC service, no HTTP server acts as an intermediary. This means you can now define the client and server-side data types and service interfaces .proto file, easy to build a true end-to-gRPC application architecture. gRPC-Web provides another alternative to REST for Web developers.

\\
base
\\
gRPC-Web so that you can use to define .proto service "contract" between client applications and back-end Web server gRPC, and automatically generate client-side JavaScript (you can choose Closure compiler or the use of more a wide range of CommonJS). You may no longer need to worry about these things: Create a custom JSON serialization and de-serialization logic to handle HTTP status code (which may vary due REST API), Content-Type negotiation.

\\
From a broader perspective of architecture, gRPC-Web so that end-gRPC possible. As shown below:

\\


\\
on the left, a client application by communicating with a gRPC Protocol Buffers back-end server, and the server is also in communication with other back-end server gRPC Protocol Buffers. On the right side, Web applications communicate with the backend server through HTTP REST API, then the server via Protocol Buffers and communicate with other back-end services.

\\
need to clearly point out that, REST application on the right does not have any problems. There are already a large number of very successful application is a server-based REST API and built, these servers use non-HTTP protocol to communicate with back-end services. But if the development process of these applications only around a protocol and a set of .proto interfaces (and a set of service contract) carried out, then you can save countless hours of time and to avoid those problems headaches. gRPC-Web benefits not only reflected in the "technical" aspects, but also in the impact on the organization. Figure in bright orange line is not just a protocol - it represents an independent source of work and cognitive load, but now, you can turn it into a bright green.

\\
GRPC-Web advantage
\\
Over time, gRPC-Web will provide a more extensive set of features. At present, I can see that:

\\
end gRPC-- described above, with gRPC-Web, you can remove the official from the technical components of REST stack, and replaced with gRPC, so you can use Protocol Buffers to create a whole RPC pipe. Imagine this scenario: a client request is forwarded to the HTTP server, HTTP server and the back end of the five gRPC services interact. You probably need to spend a lot of time to build HTTP interaction layer, because you need to build the rest of the entire pipeline. \
Closer collaboration between front-end and back-end team - look back at the chart above, after using RPC Protocol Buffers define the entire pipeline, you do not need to "micro-service team" and "client team" bundled together. Client interaction between the back end and just one more gRPC layer. \
Easy to generate client libraries - After using gRPC-Web, and the "outside" world server interaction becomes gRPC server instead of HTTP server, which means that all client libraries can be gRPC library. You need Ruby, Python, Java, and the other four languages of the client database? You no longer need to write HTTP client for all these languages. \
A gRPC-Web example
\\
The above describes some of the advantages gRPC-Web in large-scale applications. Now let's illustrate with an example: a simple TODO application. In gRPC-Web, you can start from a simple todos.proto defined as follows:

\\
\
syntax = "proto3"; \\ \ Package Todos; \\ \ Message Todo {\ = String Content. 1; \ = BOOL Finished 2; \ \\} \ {Message GetTodoRequest \ ID = Int32. 1; \} \ \ \ {TodoService-Service \ RPC GetTodoById (GetTodoRequest) Returns (Todo); \} \
\\
you can use this definition and .proto protoc CommonJS command-line tools to generate client code:

\\
\
Protoc echo.proto import_style = = \\\ --js_out CommonJS: ./ the Output \\\ --grpc-web_out = import_style = CommonJS: ./ the Output \
\\
then gets TODO list from the back-end server gRPC:

\\
\
const} = {GetTodoRequest the require ( './ todos_pb.js'); \\ \} = const {TodoServiceClient the require ( './ todos_grpc_web_pb.js'); \\ \ = const todoService new 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) = \ u0026gt; {\\ \ if (err) {\ console.log (err); \} else {\ const todo = response.todo (); \\ \ if (todo == null) {\ console.log ( `A TODO with the ID $ {todoId} was not found`); \} else {\ console.log ( ID with the TODO FETCHED $ `todoId {}: $ {todo.content ()}`); \} \} \});
\\
where no HTTP code or methods without JSON parsing, header information is not negotiated. You declare the data types and service interfaces, gRPC-Web pulled out all the boilerplate code, you're left with is a set of clean and user-friendly API.

\\
In the back end, gRPC server can use any language that supports gRPC written, including Go, Java, C ++, Ruby , Node.js and so on (see the documentation associated with the development of language https gRPC official document: // grpc .io / docs /). The last key component is the service agent. From the outset, gRPC-Web supports Envoy Acting as the default service, which provides built-in envoy.grpc_web filters can be configured with just a few lines. For more information (https://blog.envoyproxy.io/) details on Envoy blog.

\\
Next
\\
GA version of release means that the core building blocks ready to be used in a production environment. But gRPC-Web will bring a lot of other things. You can view the official roadmap (https://github.com/grpc/grpc-web/blob/master/ROADMAP.md), in order to understand the core team envisioned the future.

\\
If you are interested in contributing to gRPC-Web, the core team hope the community can help the following:

\\
front-end framework for integrated - popular front-end framework (such as React, Angular and Vue) is not officially supported gRPC-Web. We want to see these frameworks can support it, because each framework benefited from gRPC. \
Proxy-specific language support - off GA version, Envoy is gRPC-Web's default proxy, providing support through a special module. We are also very happy to see the use of a specific language development process in the other agent. Acting within the process to remove the dependence on special agents - such as Envoy and nginx-- gRPC-Web and can make it easier to use. \
----------------
Disclaimer: This article is CSDN blogger "& lt; script & gt; alert (& # 039; XSS & # 039;) " original article, follow the CC 4.0 BY -SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/cpongo3/article/details/89026509

Guess you like

Origin www.cnblogs.com/ExMan/p/12156658.html