Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Latest commit

 

History

History
29 lines (17 loc) · 1.25 KB

protobufjs.md

File metadata and controls

29 lines (17 loc) · 1.25 KB

Twirp Protobuf.js Client

This generator creates an RPC implementation for twirp that can be used with protobuf.js.

See: https://github.com/dcodeIO/ProtoBuf.js/#using-services

The pbjs and pbts commands provided by protobuf.js still need to be used to generate the protobuf client.

There is a provided example that shows how to use the generated code.

Generate Protobuf.js Code

pbjs -t static-module -w commonjs -o <path-to-project>/service.pb.js <path-to-proto-file>
pbts --no-comments -o <path-to-project>/service.pb.d.ts <path-to-project>/service.pb.js

Generate Protobuf.js Twirp Adapter

protoc --twirp_typescript_out=library=pbjs:<path-to-project> <path-to-proto-file>

Dependencies

  • axios
  • pbjs-twirp
  • protobufjs
  • typescript

Required polyfill for non-evergreen browsers

Non-evergreen browsers (like IE11) require the use of a polyfill for the Uint8Array.slice() that is needed to send protobuf over the wire. A known working polyfill that can be used it typedarray-slice. If using Anguar, just drop import 'typedarray-slice'; into polyfills.ts.