The point of this is a smal example on how you could use protobuf to send data over http. In this example i will be using Python and the packet falcon for the server. A command line tool as the client. The example will just be a simple ping/pong containing a message, channel, and PING or PONG sent to the server. The server will respond with the same message and channel and a PONG.
lets first start with the structure of the files is like the following. all files used can be found on github see source in the end of the post. a note some in the source there is some extra code that is removed to not clutter the example.
to get started we need a protobuf file that sets the format of messages that should be used.
a enum is used to hold the name/value that we like for a pingId. a PingDTO that will hold the message values that we like in the PingDTO. We then use this PingDTO in the PingCommand and the PingDocument. The PingCommand will be used to send to the server and the response will be the PingDocument.
to build the proto python file. you will get py_proto_pb2.py which is the protobuf python class file that you later use to build a proto client and server.
Server api. The server uses the generated protobuf python file to parse the command sent, and to return the document to the client.
Server function made to run the falcon app.
Starting the server by using gunicorn and calling the api falcon api
Client api. Like in the server we use the same python generated proto file. To send a command to the server and get back the response document that will be printed to stdout.
Client made as a command line tool to be able to just send some commands and then print the response. You send PING which is id 1 and you should get back id 2 from the server