njpatel/grpcc

Metadata/headers?

davedbase opened this issue · 4 comments

I'm wondering how I can add metadata? I'm trying to add an authentication method to my gRPC service and testing with grpcc will be useful. So hopefully there's a way?

This should help https://stackoverflow.com/a/37551218 . client is just the exposed grpc javascript client, so you can do all the things you can do with that.

An example of how to add metadata would be awesome. The example which was linked to is a no-brainer when using the node grpc lib, but when using this grpcc shell, it is not the same. An example, please.

The grpcc shell is just the node REPL with client, pr, and printReply exposed. That means you should be able to var grpc = require('grpc') and then create a metadata object, and finally call methods on the client exactly the same way as you would in normal code.

If this isn't working for you, then I'd be happy to debug a test case if you've got one.

Was looking into how to do this and it looks like a recent pull request added a helper method to create metadata and exposes grpc to the context by default.

You can attach metadata by using the createMetadata method or alias cm:

var meta = cm({authorization: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"})

Then pass the meta data through to your method after its request message:

client.get({id: 1}, meta, pr)