Skip to content

Protocol Buffers to HTTP client code generator/converter

License

Notifications You must be signed in to change notification settings

kodiiing/proto2http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Protocol Buffers to HTTP client code generator/converter

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •