-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose response status and metadata #3
Comments
A proposal: From an api perspective... we could keep the present api for easy of use, simplicity, and compatibility. In addition we could introduce a new "lower-level" Fluent Request API: const caller = require('grpc-caller')
const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto')
const client = caller('0.0.0.0:50051', PROTO_PATH, 'Greeter')
const req = new client.Request('sayHello', { name: 'Bob'}) // the method we wish to invoke with the params
.setOptions({}) // any normal "call" options
.setMetadata({'request-id': '1234'}) // request call metadata
.responseMetadata(true) // we care about getting the response metadata, if false we won't wait for and catch the 'metadata' event
.responseStatus(true) // we care about getting the response status, if false we won't wait for and catch the 'status' event
const res = await req.exec() // promise based, optionally take callback for callback-based API
console.log(res.response)
// the response payload / "body"
// { message: 'Hello Bob!' }
console.log(res.metadata)
// the response "header" metadata converted into a map for us
// { foo: 'bar' }
console.log(res.status)
/*
the response status / trailer metadata:
{ code: 0,
details: 'OK',
metadata: { biz: 'baz' } }
*/
console.log(res.call) // just the call instance itself We could wrap the above in an simpler functional API: const res = await client.request('sayHello', { name: 'Bob'})
.setOptions({})
.setMetadata({'request-id': '1234'})
.responseMetadata(true)
.responseStatus(true)
.exec() or callback based: client.request('sayHello', { name: 'Bob'})
.setOptions({})
.setMetadata({'request-id': '1234'})
.responseMetadata(true)
.responseStatus(true)
.exec((err, res) => {
console.log(res.response)
}) Underneath the present "simple" API would be implemented using the more verbose API. |
Hey @bojand. First, thanks for all your gRPC work with Node. I appreciate it massively! Second, how's progress coming along with this? I've seen you've got your I need access to the response metadata, hence why I'm here :) |
Hello, Yea I think I got it mostly working but wasn't really happy with the resulting API or something for some reason and I think I kind of abandoned it... Don't remember now heh. I'll have to return to this soon and review it with a clearer mind now and see what's up. |
@bojand Thank you so much for this! I've not had chance to check it out yet, but will do in a few days time. And yeah, it makes sense having |
#11 is merged and published as 0.5.0. |
Currently for unary and request stream calls there is no easy way to get metadata and status if we want those
Server:
With the core client:
The text was updated successfully, but these errors were encountered: