how to change request body to protobuf in postman script?
I am testing an api endpoint that takes a protobuf msg as body,
in golang I would do something like
protodata, err = proto.Marshal(&protoStruct)
to convert the input json string to a marshalled proto message and post it with the request. I am trying to do it in postman using scripts but I got an error importing the protobuf package
There was an error in evaluating the Pre-request Script:SyntaxError: Cannot use import statement outside a module
import { Protobuf } from 'google-protobuf';
const message = new Protobuf.Message();
message.set('msg', '{"command_code": "test_check"}');
const serialized = message.serialize();
pm.environment.set('request_body', serialized);
the input json is just
{"command_code": "test_check"}
after go code executes, I usually gets the proto binary from json in the format
"0A086669656C6431120676616C756531"
to post to the request url, I am trying to do the same with postman so that I can test it there
am I doing it wrong, is there built in support in postman to marshall json to protobuf? I even tried printing out the binary in golang then try to use it as input for postman, but the binary printout only a representation of it that's why I thought of generating it in postman
[10 184 1 10 123 10 32 32 34 102 ]
I can answer part of your question.
The Postman Sandbox only supports certain libraries.
https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-external-libraries
However, can't you just send an normal grpc request?
https://blog.postman.com/postman-now-supports-grpc/