GRPC.Service (gRPC v0.11.4)

View Source

Define gRPC service used by Stub and Server. You should use Protobuf to to generate code instead of using this module directly.

It imports DSL functions like rpc/4 and stream/1 for defining the RPC functions easily:

defmodule Greeter.Service do
  use GRPC.Service, name: "helloworld.Greeter"

  rpc :SayHello, HelloRequest, stream(HelloReply)
end

option (google.api.http) annotations are supported for gRPC http/json transcoding. Once generated the 4th argument to rpc/4 contains the Google.Api.HttpRule option.

defmodule Greeter.Service do
  use GRPC.Service, name: "helloworld.Greeter"

  rpc(:SayHello, Helloworld.HelloRequest, Helloworld.HelloReply, %{
    http: %{
      type: Google.Api.PbExtension,
      value: %Google.Api.HttpRule{
        __unknown_fields__: [],
        additional_bindings: [],
        body: "",
        pattern: {:get, "/v1/greeter/{name}"},
        response_body: "",
        selector: ""
      }
    }
  })
end

Summary

Functions

grpc_type(arg)

rpc(name, request, reply, options \\ quote do %{} end)

(macro)

rpc_options(arg)

rpc_options(arg, type)

stream(param)

Specify if the request/reply is streaming.