Skip to content
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

RPC server code example? #742

Closed
yavin5 opened this issue Apr 3, 2017 · 5 comments
Closed

RPC server code example? #742

yavin5 opened this issue Apr 3, 2017 · 5 comments

Comments

@yavin5
Copy link

yavin5 commented Apr 3, 2017

protobuf.js version: 6.6.5

Hello. I'm writing a protobuf RPC service, and client code that uses it. I read all through the documentation and examples, and what I am not seeing is: a server-side code example of an RPC server. Could someone show one, or say the reason why you don't believe there should be one shown?

I see example code, with no text near it saying whether it is meant to be a client-side example or a server-side example. Shouldn't you say that by each example? Without it being explicitly labeled, it isn't clear what code is meant to be run where, since Protobuf.js can run in Node and also in a web browser. I have concluded that some of the RPC code examples are meant to be client-side, but I haven't found any examples that are clearly server-side code, so I don't know whether Protobuf.js is meant to implement both sides of the RPC or not. In fact, the documentation doesn't mention that either (shouldn't it?).

Thanks in advance!

@dcodeIO
Copy link
Member

dcodeIO commented Apr 3, 2017

You are right, there is neither specific server-side code nor documentation currently. It is intentional, though, that the library does not make any assumptions about the actual transport channel.

Also note that such a transport channel differs significantly on the server because the server does not just send and receive messages like a client but actually processes requests.

For example, if your server is based on http requests, it'd require an http library and probably some sort of routing. The routing then defines which message type is used to decode received data, then executing specific logic and encoding a response.

Nonetheless, there are server-side RPC implementations provided for specific use cases or libraries afaik, for example one using express (seems to be a bit outdated though).

@yavin5
Copy link
Author

yavin5 commented Apr 3, 2017

Thanks for the quick reply. The express-protobuf code is an example of code that does something similar to what I'm trying to do (protobuf RPC over express), so thanks for that. It is, however, an undocumented, terse, hard to follow example. I am starting to understand it.

Even if it is intentional that Protobuf.js does not make assumptions about the transport channel, it would make the example code on your project's page much clearer if you add / modify these things in the docs:

  • State in a paragraph that Protobuf.js's code is meant to implement both the client and server side of the RPC implementation. Without this the user can only wonder whether you meant to offer code for implementing the server side (it is currently only clear that you are offering client side code).
  • Write by each code example that the following code is the same on both the client and the server side of RPC. (Even better would be to show two snippets: one that you label as the client, making a request and handling the response, and a second one that you label as the server, where it is receiving the request and doing a one liner of processing on it to generate and send a response. Without stating which it is, the user may think an example is for the client when it's for the server, and vice versa. Or, may think that it is client side only when it isn't.
  • Have one example, on your page, somewhere, showing a runnable example of a server that implements an RPC service. At least then it would be clear and explicit how even one example works to connect up a transport. It would be fine to use express for this because it is simple, and because most people will likely want to use express. Without this, the user has zero examples of how that is meant to work.

@dcodeIO
Copy link
Member

dcodeIO commented Apr 11, 2017

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!

@dcodeIO dcodeIO closed this as completed Apr 11, 2017
@yavin5
Copy link
Author

yavin5 commented Apr 11, 2017

Yes, that's fine. Thank you for your edits. I read through them and it all appeared to be helpful improvements. I'm still of the opinion that the docs are missing several fundamental things, but I may contribute to improving that in the future. Thanks for your help!

@xealot
Copy link

xealot commented Aug 31, 2017

I agree that there should be no implementation in protobufjs for an RPC server. The whole reason we're attempting to use this project is that it's hands off on the transport mechanism and is just a mature encoding/decoding library with TS support.

That being said, there should be enough in the documentation to give hints at how to implement a server. For instance, how to read a protobuf body (binary or JSON) and determine what the message is, if it's an RPC request, what method, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants