grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
861 stars 271 forks source link

[ISSUE] Option (google.api.http) Not Working! #610

Closed vzool closed 1 year ago

vzool commented 1 year ago
#### pubspec.yaml ```dart grpc: ^3.1.0 protobuf: ^2.1.0 ``` #### pubspec.lock ```dart grpc: dependency: "direct main" description: name: grpc sha256: a73c16e4f6a4a819be892bb2c73cc1d0b00e36095f69b0738cc91a733e3d27ba url: "https://pub.dev" source: hosted version: "3.1.0" protobuf: dependency: "direct main" description: name: protobuf sha256: "01dd9bd0fa02548bf2ceee13545d4a0ec6046459d847b6b061d8a27237108a08" url: "https://pub.dev" source: hosted version: "2.1.0" ``` ## Repro steps ### 1. step1 HelloWorld.proto ```js syntax = "proto3"; package helloworld.v1; import "google/api/annotations.proto"; option go_package = "aseel-server/api/helloworld/v1;v1"; option java_multiple_files = true; option java_package = "dev.kratos.api.helloworld.v1"; option java_outer_classname = "HelloworldProtoV1"; // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) { option (google.api.http) = { get: "/helloworld/{name}" }; } } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } ``` ### Expected result: send `GET` request to the endpoint `http://localhost:8080/helloworld/{name}` Based on proto file above, the request GET should be sent to `http://localhost:8080/helloworld/{name}` instead of POST request to http://localhost:8080/helloworld.v1.Greeter/SayHello. Why does it behave like that? ### Actual result: It fails and sent `POST` request instead of `GET` request to a different endpoint too. ![226554698-a90d1526-7742-4704-8dce-84f2edf31f58](https://user-images.githubusercontent.com/4952736/226586446-20bb40a7-4aaa-4bcb-be66-ba052c2f0c33.png) ![226554805-b82d945f-0f85-4328-85e9-2c6fc0560273](https://user-images.githubusercontent.com/4952736/226586469-a51752c5-b1fa-4758-8e1d-dae51d63db65.png) ## Details ```javascript ➜ protoc --version libprotoc 22.2 ➜ go version go version go1.20.1 darwin/amd64 ➜ flutter --version Flutter 3.7.7 • channel stable • https://github.com/flutter/flutter.git Framework • revision 2ad6cd72c0 (13 days ago) • 2023-03-08 09:41:59 -0800 Engine • revision 1837b5be5f Tools • Dart 2.19.4 • DevTools 2.20.1 ```
mraleph commented 1 year ago

Your package is called helloworld.v1 and your service is called Greeter so naturally the path is helloworld.v1.Greeter.

vzool commented 1 year ago

Your package is called helloworld.v1 and your service is called Greeter so naturally the path is helloworld.v1.Greeter.

Yeah, but even this http://localhost:8080/helloworld.v1.Greeter/SayHello is not working. It says 404 NOT FOUND 226554698-a90d1526-7742-4704-8dce-84f2edf31f58

mraleph commented 1 year ago

Oh, I see you are using google.api.http. This annotation is for the gRPC->REST transcoding and has no effect on grpc-dart package.

I can't really say why your server reports 404 without knowing what you do on the server. Is it a Dart server? Is it some other server? How is it configured etc.