1

I have an existing java grpc server file that is generated from a .proto file. I need to add HTTP REST API endpoints for each of the rpc calls in my .proto file. Probably using google.api.http.

The .proto file looks something like:

rpc GetShelves(GetShelvesRequest) returns (stream Shelf);

In the grpc service, this turns into:

public StreamObserver<GetShelvesRequest> GetShelves( StreamObserver<GetShelvesResponse> responseObserver) { /* do something */ }

However, the StreamObserver is a class provided by gRPC and it's not applicable for HTTP. Ideally, I'd use the StreamingResponseBody interface in Spring MVC to write directly to the response body as bytes are available in my REST endpoint. However I want to reuse the same .proto file to enforce consistency across my two API endpoints.

From the google.api.http documentation for transcoding, I should add an annotation like:

rpc GetShelves(GetShelvesRequest) returns (stream Shelf) { option (google.api.http) = { get: "/v1/shelves/" }; }

To add an http end point. But the stream keyword will generate a SteamObserver.

How do I use the same .proto file, but have the end result be a StreamObserver for grpc but a StreamingResponseBody for http?

n/a, described above.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.