有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
Response 是 Client.invoke 执行方法的返回对象。

字段

字段
类型
描述
code
number
状态码
data
any
业务返回数据
headers
Record<string, string[]>
请求 Header 元数据
message
string
错误信息
trailers
Record<string, string[]>
请求 Trailer 元数据

样例

调用 Client.invoke 获得请求返回对象:
import grpc from 'pts/grpc';

// 创建新的 grpc Client
const client = new grpc.Client();

// 加载协议文件根目录中的 addsvc.proto
client.load([], 'addsvc.proto');

export default () => {
// 建立连接
client.connect('grpcb.in:9000', { insecure: true });

// 调用方法,获得请求的返回对象 rsp
const rsp = client.invoke('addsvc.Add/Sum', {
a: 1,
b: 2,
});
console.log(rsp.data.v); // 3

// 关闭连接
client.close();
};