# gRPC Elixir

[![Travis Status](](
[![GitHub actions Status](](
[![Last Updated](](
[![Total Download](](

An Elixir implementation of [gRPC](

## Table of contents

- [Notice](#notice)
- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [Benchmark](#benchmark)
- [Contributing](#contributing)

## Notice
> __Note__
> The [Gun]( library doesn't have a full 2.0 release yet, so we depend on `:grcp_gun 2.0.1` for now.
This is the same as `:gun 2.0.0-rc.2`, but [Hex]( doesn't let us depend on RC versions for releases.

## Installation

The package can be installed as:

  def deps do
      {:grpc, "~> 0.5.0"},
      # We don't force protobuf as a dependency for more
      # flexibility on which protobuf library is used,
      # but you probably want to use it as well
      {:protobuf, "~> 0.11"}

## Usage

1. Generate Elixir code from proto file as [protobuf-elixir]( shows(especially the `gRPC Support` section).

2. Implement the server side code like below and remember to return the expected message types.

defmodule Helloworld.Greeter.Server do
  use GRPC.Server, service: Helloworld.Greeter.Service

  @spec say_hello(Helloworld.HelloRequest.t, GRPC.Server.Stream.t) :: Helloworld.HelloReply.t
  def say_hello(request, _stream) do "Hello #{}")

3. Start the server

You can start the gRPC server as a supervised process. First, add `GRPC.Server.Supervisor` to your supervision tree.

# Define your endpoint
defmodule Helloworld.Endpoint do
  use GRPC.Endpoint

  intercept GRPC.Server.Interceptors.Logger
  run Helloworld.Greeter.Server

# In the start function of your Application
defmodule HelloworldApp do
  use Application
  def start(_type, _args) do
    children = [
      # ...
      {GRPC.Server.Supervisor, endpoint: Helloworld.Endpoint, port: 50051}

    opts = [strategy: :one_for_one, name: YourApp]
    Supervisor.start_link(children, opts)

4. Call rpc:

iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
iex> request = "grpc-elixir")
iex> {:ok, reply} = channel |> Helloworld.Greeter.Stub.say_hello(request)

# With interceptors
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [GRPC.Client.Interceptors.Logger])

Check [examples](examples) and [interop](interop)(Interoperability Test) for some examples.

## Features

- Various kinds of RPC:
  - [Unary](
  - [Server-streaming](
  - [Client-streaming](
  - [Bidirectional-streaming](
- [TLS Authentication](
- [Error handling](
- Interceptors(See [`GRPC.Endpoint`](
- [Connection Backoff](
- Data compression

## Benchmark

1. [Simple benchmark](examples/helloworld/ by using [ghz](

2. [Benchmark](benchmark) followed by official spec

## Contributing

Your contributions are welcome!

Please open issues if you have questions, problems and ideas. You can create pull
requests directly if you want to fix little bugs, add small features and so on.
But you'd better use issues first if you want to add a big feature or change a
lot of code.