Closed vietj closed 3 months ago
Support JSON wire format, documentation excerpts:
gRPC implicitly assumes the usage of the Protobuf wire format.
The Vert.x gRPC server supports the JSON wire format as well.
You can use a JSON service method to bind a service method accepting requests carrying the application/grpc+json content-type.
application/grpc+json
server.callHandler(VertxGreeterGrpcServer.SayHello_JSON, request -> { request.last().onSuccess(helloRequest -> { request.response().end(HelloReply.newBuilder() .setMessage("Hello " + helloRequest.getName()).build() ); }); });
NOTE: JSON encoding/decoding is achieved by com.google.protobuf:protobuf-java-util library.
com.google.protobuf:protobuf-java-util
Anemic JSON is also supported with Vert.x JsonObject
JsonObject
ServiceMethod<JsonObject, JsonObject> sayHello = ServiceMethod.server( ServiceName.create("helloworld", "Greeter"), "SayHello", GrpcMessageEncoder.JSON_OBJECT, GrpcMessageDecoder.JSON_OBJECT ); server.callHandler(sayHello, request -> { request.last().onSuccess(helloRequest -> { request.response().end(new JsonObject().put("message", "Hello " + helloRequest.getString("name"))); }); });
The Vert.x gRPC client supports the JSON wire format as well.
You can call a JSON service method accepting requests carrying the application/grpc+json content-type.
client .request(server, VertxGreeterGrpcClient.SayHello_JSON).compose(request -> { request.end(HelloRequest .newBuilder() .setName("Bob") .build()); return request.response().compose(response -> response.last()); }).onSuccess(reply -> { System.out.println("Received " + reply.getMessage()); });
ServiceMethod<JsonObject, JsonObject> sayHello = ServiceMethod.client( ServiceName.create("helloworld", "Greeter"), "SayHello", GrpcMessageEncoder.JSON_OBJECT, GrpcMessageDecoder.JSON_OBJECT ); client .request(server, sayHello).compose(request -> { request.end(new JsonObject().put("name", "Bob")); return request.response().compose(response -> response.last()); }).onSuccess(reply -> { System.out.println("Received " + reply.getString("message")); });
Support JSON wire format, documentation excerpts:
Vert.x gRPC Server
JSON wire format
gRPC implicitly assumes the usage of the Protobuf wire format.
The Vert.x gRPC server supports the JSON wire format as well.
You can use a JSON service method to bind a service method accepting requests carrying the
application/grpc+json
content-type.NOTE: JSON encoding/decoding is achieved by
com.google.protobuf:protobuf-java-util
library.Anemic JSON is also supported with Vert.x
JsonObject
Vert.x gRPC Client
JSON wire format
gRPC implicitly assumes the usage of the Protobuf wire format.
The Vert.x gRPC client supports the JSON wire format as well.
You can call a JSON service method accepting requests carrying the
application/grpc+json
content-type.NOTE: JSON encoding/decoding is achieved by
com.google.protobuf:protobuf-java-util
library.Anemic JSON is also supported with Vert.x
JsonObject