Comments (6)
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" Request
and Response
API, something similar to:
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.
from grpc-caller.
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 req_res
branch in progress and it's looking good so far!
I need access to the response metadata, hence why I'm here :)
from grpc-caller.
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.
from grpc-caller.
@yoitsro I believe #11 adds the functionality. Please provide feedback on the new API. Note that now you have to explicitly add grpc
dependency in your package.json
. Thanks!
from grpc-caller.
@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 grpc
required separately. It's similar to what I do with https://github.com/yoitsro/joigoose and mongoose
:)
from grpc-caller.
#11 is merged and published as 0.5.0.
from grpc-caller.
Related Issues (20)
- Namespace issue with same service name HOT 3
- Not work with package name HOT 1
- Clearly document how to read a streaming response HOT 5
- Is it a pure js module for grpc? HOT 6
- Absolute paths in includeDirs HOT 1
- What is serviceWrapper in the static example? HOT 6
- options.retry on the client is not working
- throw error when status code 0 HOT 1
- How to define client interceptors
- Use typescript Ctor is not a constructor HOT 2
- Return data is missing
- Question - TypeScript support and type declarations HOT 2
- How to set SetMaxMessageSize?
- Error: 2 UNKNOWN: Stream removed HOT 1
- need some hook
- replace `grpc` with `grpc-js`? HOT 2
- how to use dynamic client with nested protos?
- Cannot create a caller instance with retry options
- @grpc/grpc-js get error "Channel credentials must be a ChannelCredentials object" HOT 1
- Requirement on @grpc/grpc-js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-caller.