Proto2http provides a code generation tool to convert your protocol buffers (.proto) files into invokable HTTP request.
proto2http -path=your-file.proto -output=../generated_protos/ -baseurl=https://your-api-path.com -target=language-target
See proto2http -help
for more detail.
Converted files from gRPC's official sample HelloWorld.proto invoked with command:
proto2http -path=test.proto -target=browser-ts -baseurl=http://test-api.com/
/**
* The request message containing the user's name.
*/
type HelloRequest = {
name: string
}
/**
* The response message containing the greetings
*/
type HelloReply = {
message: string
}
/**
* The greeting service definition.
*/
export class GreeterClient {
_baseUrl: string
constructor(baseUrl?: string) {
if (baseUrl === "" || baseUrl == null) {
this._baseUrl = "http://test-api.com/";
} else {
this._baseUrl = baseUrl;
}
}
/**
* Sends a greeting
*/
public async SayHello(input: HelloRequest): Promise<HelloReply> {
const request = await fetch(
new URL("SayHello", this._baseUrl).toString(),
{
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(input),
}
);
const body = await request.json();
return body;
}
}
For all client and server samples of router_guide.proto, see this gist.
See RELEASES page.
Available systems: MacOS AMD64, Linux 386, Linux AMD64, Linux ARM, Linux ARM64, Windows 386, Windows AMD64, Windows ARM.
go install github.com/kodiiing/proto2http@latest
You will need Go 1.17+
go build -o proto2http cmd/main.go
mv proto2http /usr/local/bin/proto2http