0

i'm using nest and GRPC microservice to build my backend.

so first i have created rest api and now i'm converting it to GRPC call.

so my api response is as follows:

{
"data": {
    "2-2-2-2": [             //id
        [
            24.942795,       //lat
            60.17088         //lng
        ]
    ]
}

}

protofile:

    syntax = "proto3";
package LocationTracking;

service LocationTrackingService {
  rpc getLocations(GetLocationInputs) returns (GetLocationResponse);
 
}

     message GetLocationInputs {
    string assetIds = 1;
    optional string from = 4;
    optional string to = 5;
    
  }

  message GetLocationResponse {
   
  }

so how should i structure GetLocationResponse message for this kind of response?

Jay Desani
  • 11
  • 2

1 Answers1

0

I think you can use Maps type to define your GetLocationResponse and a message Location to define your two values

Example

syntax = "proto3";

package location.tracking

message Location {
    double lat;
    double lng;
}

service LocationTrackingService {
  rpc getLocations(GetLocationRequest) returns (GetLocationResponse);
}

message GetLocationRequest {
  string assetIds = 1;
  optional string from = 4;
  optional string to = 5;  
}

message GetLocationResponse {
  map<string, Location> data = 1;   
}

I also recommend you Google naming convention to keep a consistant standard naming in your protobuf.