protoc generate typescript by http
Go to file
yanweidong 146747cece fix generate const 2025-04-17 09:00:20 +08:00
.sage dev 2025-04-12 12:38:00 +08:00
examples/proto dev 2025-04-12 12:38:00 +08:00
internal dev 2025-04-17 00:10:46 +08:00
.eslintrc.js dev 2025-04-12 12:38:00 +08:00
.gitignore dev 2025-04-12 12:38:00 +08:00
.goreleaser.yml dev 2025-04-12 12:38:00 +08:00
CODE_OF_CONDUCT.md dev 2025-04-12 12:38:00 +08:00
LICENSE dev 2025-04-12 12:38:00 +08:00
Makefile dev 2025-04-12 12:38:00 +08:00
README.md dev 2025-04-12 12:38:00 +08:00
SECURITY.md dev 2025-04-12 12:38:00 +08:00
go.mod dev 2025-04-17 00:10:46 +08:00
go.sum dev 2025-04-17 00:10:46 +08:00
main.go fix generate const 2025-04-17 09:00:20 +08:00

README.md

protoc-gen-typescript-http

Generates Typescript types and service clients from protobuf definitions annotated with http rules. The generated types follow the canonical JSON encoding.

Experimental: This library is under active development and breaking changes to config files, APIs and generated code are expected between releases.

Using the plugin

For examples of correctly annotated protobuf defintions and the generated code, look at examples.

Install the plugin

go get git.apinb.com/bsm-tools/protoc-gen-ts

Or download a prebuilt binary from releases.

Invocation

protoc 
  --typescript-http_out [OUTPUT DIR] \
  [.proto files ...]

The generated clients can be used with any HTTP client that returns a Promise containing JSON data.

const rootUrl = "...";

type Request = {
  path: string,
  method: string,
  body: string | null
}

function fetchRequestHandler({path, method, body}: Request) {
  return fetch(rootUrl + path, {method, body}).then(response => response.json())
}

export function siteClient() {
  return createShipperServiceClient(fetchRequestHandler);
}