Craig Tiller
dbb5164ac7
Closes #37820 PiperOrigin-RevId: 682352913 |
2 months ago | |
---|---|---|
.. | ||
BUILD | [Example] Added gRPC C++ generic API example (#35411) | 10 months ago |
CMakeLists.txt | [Build] Bumped the minimum version of cmake (#37702) | 2 months ago |
README.md | [Example] Added gRPC C++ generic API example (#35411) | 10 months ago |
greeter_client.cc | [clang-format] Remove custom clang-format rules for include ordering (#37820) | 2 months ago |
greeter_server.cc | [clang-format] Remove custom clang-format rules for include ordering (#37820) | 2 months ago |
README.md
Generic API Example
Overview
While generated stub code is often the simpler and best choice for sending and handling API calls, generic APIs offer unique advantages in specific scenarios, such as proxy implementation. Their ability to manage multiple message types with a single function makes them particularly handy in these cases. This example demonstrates how to use generic APIs to achieve this flexibility.
This example implements greeter_callback_client
and greeter_callback_server
using the generic APIs.
Therefore, looking at the difference would be helpful to understand how to use generic APIs.
Try it!
Once you have working gRPC, you can build this example using either bazel or cmake.
Run the server, which will listen on port 50051:
$ ./greeter_server
Run the client (in a different terminal):
$ ./greeter_client
If things go smoothly, you will see the client output:
### Send: SayHello(name=World)
Ok. ReplyMessage=Hello World
### Send: SayHello(name=gRPC)
Ok. ReplyMessage=Hello gRPC