https://github.com/einride/protoc-gen-typescript-http
Generate types and service clients from protobuf definitions annotated with http rules.
https://github.com/einride/protoc-gen-typescript-http
protobuf protoc typescript
Last synced: 3 months ago
JSON representation
Generate types and service clients from protobuf definitions annotated with http rules.
- Host: GitHub
- URL: https://github.com/einride/protoc-gen-typescript-http
- Owner: einride
- License: mit
- Created: 2021-03-07T18:33:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-10-01T10:03:20.000Z (9 months ago)
- Last Synced: 2025-10-09T00:06:00.208Z (9 months ago)
- Topics: protobuf, protoc, typescript
- Language: Go
- Homepage:
- Size: 221 KB
- Stars: 48
- Watchers: 3
- Forks: 12
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# protoc-gen-typescript-http
Generates Typescript types and service clients from protobuf definitions
annotated with
[http rules](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto).
The generated types follow the
[canonical JSON encoding](https://developers.google.com/protocol-buffers/docs/proto3#json).
**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](./examples).
### Install the plugin
```bash
go get go.einride.tech/protoc-gen-typescript-http
```
Or download a prebuilt binary from [releases](./releases).
### Invocation
```bash
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.
```typescript
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);
}
```