I am trying to call a GRPC endpoint but I want to provide a customer auth header. Where do I specify this?
var client = new proto.Publisher('127.0.0.1:50051',
grpc.credentials.createInsecure());
var customHeader = {
'authorization': 'secret'
}
client.publish(data, function (err, response) {
console.log('Sent');
});
Headers passed in gRPC communication are categorized into two types: call-definition headers and custom metadata. Call-definition headers are predefined headers supported by HTTP/2. Those headers should be sent before custom metadata.
Your scripts should be like this: Now, to run the code open your terminal and run npm run grpc-server to start your server. Then open another terminal and run npm run grpc-client and you would get the results on your terminal.
Building gRPC Web clients In the case of gRPC-web client, an npm package is generated and then published to the GitHub package repository. Then, JavaScript applications can consume this package using the npm install command.
You need to create a grpc.Metadata
object, then pass it as an optional argument to the method:
var client = new proto.Publisher('127.0.0.1:50051',
grpc.credentials.createInsecure());
var metadata = new grpc.Metadata();
metadata.add('authorization', 'secret')
client.publish(data, metadata, function (err, response) {
console.log('Sent');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With