bdledger-apis/grpc/README.md
2024-03-06 15:37:53 +08:00

2.3 KiB

BDLedger API

Documentation

See API documentation

Development

Generating gRPC code in languages

Installling tools

Download the Protocol Buffers compiler (protoc-25.3-*)+ for your platform and add protoc to PATH environment variable

For generating Go code, install protoc-gen-go (v1.33.0+):

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

Also install protoc-gen-go-grpc v1.3.0+:

go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

For generating HTTP JSON APIs with grpc-gateway v2.2.0, follow the documentation.

For generating validators, install go-proto-validators v0.3.2+:

go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators@latest

For generating Java code: From bdledger-sdk-java run gradle generateProto

For generating Node.js code and/or TypeScript definitions), install Node.js then run:

npm install

For frontend JavaScript:

git clone https://github.com/grpc/grpc-web
cd grpc-web
sudo make install-plugin

References:

TODO: Look into protobuf.js for Nodes.js and frontend TODO: Look into Kroto+ for Kotlin

Generating code

Run:

For generating TypeScript client code with ts-proto, run:

invoke gen -t ts

For generating TypeScript definitions to be used with @grpc/proto-loader, run:

invoke gen -t types

Others:

./scripts/gen [-a, --async] [go] [gohttp] [nodejs] [docs]

nodejs: For generating static Node.js code and TypeScript definitions

Use -a or --async to speed up generation by asynchronously and concurrently generating all code and documentation ( script will exit without waiting for completion)

Generating documentation

Install Go then run:

go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
./scripts/gen [-a, --async] docs