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.
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
protoc --twirp_typescript_out=library=pbjs:<path-to-project> <path-to-proto-file>
- axios
- pbjs-twirp
- protobufjs
- typescript
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
.