1

I'm new in using gRPC with proto3, and I've used Transcoding HTTP/JSON to gRPC to migrate existing http endpoints to grpc.

But I have http DELETE request with request body. I have tried following and got an error.

Grpc Endpoint :

  rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse) {
    option (google.api.http) = {
      delete: "/v2/file/delete/{path}"
      body: "*"
    };
  }

protoc gererate command as below

protoc -I ./proto --go-grpc_out=. --go_out=. --grpc-gateway_out=. --openapiv2_out=./openapi ./proto/myapp.proto

Error I have Got

--grpc-gateway_out: must not set request body when http method is DELETE except allow_delete_body option is true

And then I have add --allow_delete_body=true to my protoc command as below.

--allow_delete_body=true
error : Unknown flag: --allow_delete_body

--grpc-gateway_opt allow_delete_body=true 
error : must not set request body when http method is DELETE except allow_delete_body option is true

grpc versions in my go.mod

github.com/grpc-ecosystem/grpc-gateway/v2 v2.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
google.golang.org/genproto v0.0.0-20210224155714-063164c882e6
google.golang.org/grpc v1.36.0
google.golang.org/protobuf v1.26.0

Would anyone kindly explain How I transcode HTTP DELETE to grpc with request body.

nipuna
  • 3,697
  • 11
  • 24

2 Answers2

1

The protoc always has wired issues. Suggest use buf instead. And the config of buf.gen.yaml should like this and it works well:

version: v1beta1
plugins:
  - name: go
    out: proto
    opt: paths=source_relative
  - name: go-grpc
    out: proto
    opt: paths=source_relative,require_unimplemented_servers=false
  - name: grpc-gateway
    out: proto
    opt:
      - paths=source_relative
      - allow_delete_body=true

For this question, I found answer in Not able to pass allow_delete_body to protoc-gen-grpc-gateway, this command works for me, but not work after add --openapiv2_out=./openapi:

protoc -I ./proto --go-grpc_out=. --go_out=. --grpc-gateway_out=allow_delete_body=true:. ./proto/myapp.proto
HelloWood
  • 727
  • 4
  • 13
  • Thanks for the response. But I can not change protoc at the moment. So I need to find a way to do this with protoc. For the future development, I will keep in mind your suggestion. – nipuna Jun 22 '21 at 02:38
  • Updated the question with that. – nipuna Jun 22 '21 at 03:46
1

After spent time on web and trying with applying flags in different ways, I have found the working command for me. Thanks everyone help to resolve this.

This is the working command for me:

protoc -I ./proto --go-grpc_out=. --go_out=. --grpc-gateway_out=allow_delete_body=true:. --openapiv2_opt allow_delete_body=true --openapiv2_out=./openapi ./proto/myapp.proto 
nipuna
  • 3,697
  • 11
  • 24