gRPC Web Native simplifies the process of generating client-side JavaScript or TypeScript code from .proto files for web browsers. By leveraging modern web APIs, it supports streaming and HTTP/2 without the complexity of traditional proxies, making it easier to implement robust gRPC services in web applications.
gRPC Web Native is a powerful toolchain designed for generating native gRPC client code in JavaScript (TypeScript) for web browsers from .proto files. It utilizes protobuf.js as its core code generator and integrates with grpc-node (npm package @grpc/grpc-js) to facilitate server implementations. This enables seamless communication between the front-end and gRPC backend, enhancing application performance and user experience.
Content-Type: application/grpc+proto handling. This means that it can transmit data efficiently using ReadableStream and Uint8Array, which is ideal for scenarios involving byte streams.fetch, gRPC Web Native offers HTTP/2 support without the need for WebTransport, which allows for efficient data fetching and is compatible across modern browsers.AbortController, providing a better control mechanism for managing HTTP calls.protoc.To generate the web client protocols from the source files, use the following commands:
npm run transpile-generator
npm run gen-web-client-protos <protos_source> <output_folder>
For instance:
npm run gen-web-client-protos './protos/*.proto' ./src/generated
For more examples and practical implementations, refer to Example.tsx.
When using this library with a NodeJS gRPC server implementation like gRPC-node, proper editing of the CORS configuration is required for successful communication. Example configurations can be followed from the gRPC server's code.
By allowing straightforward integration and efficient data handling, gRPC Web Native empowers developers to build robust web applications that efficiently communicate with backend gRPC services.
No comments yet.
Sign in to be the first to comment.