0

I implemented grpc server with reversed http proxy gateway as per numerous examples and it works fine. I have simple protofile like

syntax = "proto3";

package altconfig;

option go_package = "/proto";

import "google/api/annotations.proto";

service ConfigService {
  rpc CreateConfig (Config) returns (Config) {
    option (google.api.http) = {
      post: "/api/v1/config"
      body: "*"
    };
  }
}

message Config {
  uint32 id = 1;
  string name = 2;
}

I have compilled protobuf stubs I have workable code in main.go that starts grpc server, client connection and http server

my function to implement CreateConfig just prints serialized object:

func (s *server) CreateConfig(ctx context.Context, in *con.Config) (*con.Config, error) {
    log.Println(in)
    return in, nil
}

When I do POST request in postman with JSON body:

{
  "id": 33333, 
  "name": "paprika"
}

I get empty response

{
    "id": 0,
    "name": ""
}

I exepect to get data from the request body in POST request

My curl request >curl -d '{"id":3,"name":"paprika"}' -H "Content-Type: application/json" -X POST http://localhost:8081/api/v1/config returns log {"code":3,"message":"invalid character '\'' looking for beginning of value","details":[]}

Does anybody knows what's the reason, how to solve it and get in response the protobuf Config message

RetVizan
  • 1
  • 1
  • The response from postman is consistent with no request body being sent - unfortunately there isn't enough information to diagnose the cause. The response when sending a request via curl implies the payload contains a leading single quote, which is odd considering what you've provided. I don't get the same response when using the same proto definitions, etc: https://gist.github.com/nick-jones/733e919cb96fbd2dc8a16958fc101b50 – nj_ Nov 27 '22 at 10:42
  • Added Content-Length in Postman with value and now it works Also managed to do it via CURL request, but already forgot what worked out, seems backslash for all quotes \" – RetVizan Dec 14 '22 at 11:29

0 Answers0