proto2http

module
v0.0.0-...-129f1a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2024 License: MIT

README

Proto2http

Proto2http provides a code generation tool to convert your protocol buffers (.proto) files into invokable HTTP request.

Usage

proto2http -path=your-file.proto -output=../generated_protos/ -baseurl=https://your-api-path.com -target=language-target

See proto2http -help for more detail.

Samples

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.

Installation

Precompiled binary

See RELEASES page.

Available systems: MacOS AMD64, Linux 386, Linux AMD64, Linux ARM, Linux ARM64, Windows 386, Windows AMD64, Windows ARM.

Install it as a Go binary
go install github.com/kodiiing/proto2http@latest
Build from source

You will need Go 1.17+

go build -o proto2http cmd/main.go
mv proto2http /usr/local/bin/proto2http

License

MIT

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL