Skip to content

Generate types and service clients from protobuf definitions annotated with http rules.

License

Notifications You must be signed in to change notification settings

go-kratos/protoc-gen-typescript-http

 
 

Repository files navigation

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 install github.com/go-kratos/protoc-gen-typescript-http@latest

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);
}

About

Generate types and service clients from protobuf definitions annotated with http rules.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 95.4%
  • Makefile 3.9%
  • JavaScript 0.7%