<commit_before># grpc-gateway

grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf).
It reads [gRPC](http://github.com/grpc/grpc-common) service definition,
and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.

It helps you to provide your APIs in both gRPC and RESTful style at the same time.

## Background
gRPC is great -- it generates API clients and server stubs in many programming languages,
it is fast, easy-to-use, bandwidth-efficient and its design is combat-proven by Google.
However, you might still want to provide classic RESTful APIs too for some reasons --
compatiblity to languages not supported by gRPC, API backward-compatibility or aesthetics
of RESTful architecture.

That's what grpc-gateway helps you to do. You just need to implement your gRPC service with a small amount of custom options.
Then the reverse-proxy generated by grpc-gateway serves RESTful API on top of the gRPC service.

## Installation
First you need to install ProtocolBuffers 3.0 or later.

```sh
mkdir tmp
cd tmp
git clone https://github.com/google/protobuf
./autogen.sh
./configure
make
make check
sudo make install
```

Then, `go get` as usual.

```sh
go get github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway
go get github.com/golang/protobuf/protoc-gen-go
```
 
## Usage
Make sure that your `$GOPATH/bin` is in your `$PATH`.

1. Define your service in gRPC
   
   your_service.proto:
   ```protobuf
   syntax = "proto3";
   package example;
   message StringMessage {
     string value = 1;
   }
   
   service YourService {
     rpc Echo(StringMessage) returns (StringMessage) {}
   }
   ```
2. Add a custom option to the .proto file
   
   your_service.proto:
   ```diff
    syntax = "proto3";
    package example;
   +
   +import "github.com/gengo/grpc-gateway/third_party/googleapis/google/api/annnotations.proto";
   +
    message StringMessage {
      string value = 1;
    }
    
    service YourService {
   -  rpc Echo(StringMessage) returns (StringMessage) {}
   +  rpc Echo(StringMessage) returns (StringMessage) {
   +    option (google.api.http) = {
   +      path: "/v1/example/echo"
   +      method: "POST"
   +    };
   +  }
    }
   ```
3. Generate gRPC stub
   
   ```sh
   protoc -I/usr/local/include -I. -I$GOPATH/src \
     --go_out=plugins=grpc:. \
     path/to/your_service.proto
   ```
   
   It will generate a stub file `path/to/your_service.pb.go`.
4. Implement your service in gRPC as usual
   1. (Optional) Generate gRPC stub in the language you want.
     
     e.g.
     ```sh
     protoc -I/usr/local/include -I. -I$GOPATH/src --ruby_out=. \
       path/to/your/service_proto
     
     protoc -I/usr/local/include -I. -I$GOPATH/src \
       --plugin=protoc-gen-grpc-ruby=grpc_ruby_plugin \
       --grpc-ruby_out=. \
       path/to/your/service.proto
     ```
   2. Implement your service
4. Generate reverse-proxy
   
   ```sh
   protoc -I/usr/local/include -I. -I$GOPATH/src \
     --grpc-gateway_out=logtostderr=true:. \
     path/to/your_service.proto
   ```
   
   It will generate a reverse proxy `path/to/your_service.pb.gw.go`.
5. Write an entrypoint
   
   Now you need to write an entrypoint of the proxy server.
   ```go
   package main
   import (
     "flag"
     "net/http"
   <commit_msg>Renumber an ordered list<commit_after># grpc-gateway

grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf).
It reads [gRPC](http://github.com/grpc/grpc-common) service definition,
and generates a reverse-proxy server which translates a RESTful JSON API into gRPC.

It helps you to provide your APIs in both gRPC and RESTful style at the same time.

## Background
gRPC is great -- it generates API clients and server stubs in many programming languages,
it is fast, easy-to-use, bandwidth-efficient and its design is combat-proven by Google.
However, you might still want to provide classic RESTful APIs too for some reasons --
compatiblity to languages not supported by gRPC, API backward-compatibility or aesthetics
of RESTful architecture.

That's what grpc-gateway helps you to do. You just need to implement your gRPC service with a small amount of custom options.
Then the reverse-proxy generated by grpc-gateway serves RESTful API on top of the gRPC service.

## Installation
First you need to install ProtocolBuffers 3.0 or later.

```sh
mkdir tmp
cd tmp
git clone https://github.com/google/protobuf
./autogen.sh
./configure
make
make check
sudo make install
```

Then, `go get` as usual.

```sh
go get github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway
go get github.com/golang/protobuf/protoc-gen-go
```
 
## Usage
Make sure that your `$GOPATH/bin` is in your `$PATH`.

1. Define your service in gRPC
   
   your_service.proto:
   ```protobuf
   syntax = "proto3";
   package example;
   message StringMessage {
     string value = 1;
   }
   
   service YourService {
     rpc Echo(StringMessage) returns (StringMessage) {}
   }
   ```
2. Add a custom option to the .proto file
   
   your_service.proto:
   ```diff
    syntax = "proto3";
    package example;
   +
   +import "github.com/gengo/grpc-gateway/third_party/googleapis/google/api/annnotations.proto";
   +
    message StringMessage {
      string value = 1;
    }
    
    service YourService {
   -  rpc Echo(StringMessage) returns (StringMessage) {}
   +  rpc Echo(StringMessage) returns (StringMessage) {
   +    option (google.api.http) = {
   +      path: "/v1/example/echo"
   +      method: "POST"
   +    };
   +  }
    }
   ```
3. Generate gRPC stub
   
   ```sh
   protoc -I/usr/local/include -I. -I$GOPATH/src \
     --go_out=plugins=grpc:. \
     path/to/your_service.proto
   ```
   
   It will generate a stub file `path/to/your_service.pb.go`.
4. Implement your service in gRPC as usual
   1. (Optional) Generate gRPC stub in the language you want.
     
     e.g.
     ```sh
     protoc -I/usr/local/include -I. -I$GOPATH/src --ruby_out=. \
       path/to/your/service_proto
     
     protoc -I/usr/local/include -I. -I$GOPATH/src \
       --plugin=protoc-gen-grpc-ruby=grpc_ruby_plugin \
       --grpc-ruby_out=. \
       path/to/your/service.proto
     ```
   2. Implement your service
5. Generate reverse-proxy
   
   ```sh
   protoc -I/usr/local/include -I. -I$GOPATH/src \
     --grpc-gateway_out=logtostderr=true:. \
     path/to/your_service.proto
   ```
   
   It will generate a reverse proxy `path/to/your_service.pb.gw.go`.
6. Write an entrypoint
   
   Now you need to write an entrypoint of the proxy server.
   ```go
   package main
   import (
     "flag"
     "net/http"
   
{'fraction_non_alphanumeric': 0.10684474123539232, 'fraction_numerical': 0.004553042950371832, 'mean_word_length': 2.7443181818181817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3414494', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2128, 'n_words': 677}