ts-twirp
ts-twirp is a TypeScript code generator for Twirp servers and clients.
The client portion of this library is nascent.
Make a Twirp Server
Install ts-twirp
.
npm install --save-dev ts-twirp
ts-twirp takes an opinionated approach to file organization. Each protobuf
file lives in its own directory and ts-twirp generates sibling files that you
can .gitignore
.
Place your server's protobuf file in its own directory.
/src
/twirp
service.proto
Run ts-twirp
on service.proto
.
npx ts-twirp src/twirp/service.proto
This generates sibling files in the same directory.
/src
/twirp
index.ts # Exports the code you'll use to implement your server
service.pb.d.ts # Protobuf types generated from your service.proto file
service.pb.ts # Runtime protobuf serialization/deserialization code
service.proto # The service protobuf definition
server.ts # Runtime TypeScript server code
Use src/twirp/index.ts
as the entry point to the service types and runtime
code.
// ./src/server.ts;; ; http.createServerhandler.listen8000;
Make a Twirp Client
Running the generator will create both a protobuf and a JSON client.
Using the protobuf client:
; run;
As you might expect using the JSON client is nearly identical.
; run;