Exercise: Tokenize Server Streaming RPC
Implement a server streaming RPC in the text editor system which sends a stream of tokens in response to a request string.
Tokenize text RPC
In this exercise, your goal is to implement a tokenize
RPC Server Streaming API in a TextEditorService
.
The function takes a
TokenizeRequest
message that contains a string and a delimiter.It returns a stream of
Result
messages where each message represents a tokenized part of the original string.
Follow these steps:
Define the RPC in a .proto file: Define the RPC in the service definition in the proto file.
Implement the server code: Implement the server logic to handle the request and return the tokenized response.
Test the server code by implementing the client: Ensure the client can send a string and delimiter, and the server responds with a stream of tokenized strings.
The client will send the string “hello world from gRPC!” with a space token, and the server will respond with a stream of “hello”, “world”, “from”, and “gRPC!”. ...