rosenbergm / elm-grpc / Rpc

The Rpc module allows you to communicate with a gRPC-web server.

Defining a communication channel


type Client
    = Client String

Defines a gRPC client with a hostname.

backend : Client
backend =
    Client "http://localhost:9001"


type Rpc msg req res
    = Rpc Service String (Result Http.Error res -> msg) (req -> Protobuf.Encode.Encoder) (Protobuf.Decode.Decoder res)

Defines an RPC which will be called on a Service.

backend : Client
backend =
    Client "http://localhost:9001"

userService : Service
userService =
    Service "UserService" backend

getUser : Rpc Msg UserRequest UserResponse
getUser =
    Rpc userService "GetUser" ReceiveUser encodeUserRequest decodeUserResponse


type Service
    = Service String Client

Defines a gRPC service attached to a Client.

backend : Client
backend =
    Client "http://localhost:9001"

userService : Service
userService =
    Service "UserService" backend

Executing requests

unary : Rpc msg req res -> req -> Platform.Cmd.Cmd msg

Execute a unary RPC on a gRPC-web server running on the specified host.

backend : Client
backend =
    Client "http://localhost:9001"

userService : Service
userService =
    Service "UserService" backend

getUser : Rpc Msg UserRequest UserResponse
getUser =
    Rpc userService "GetUser" ReceiveUser encodeUserRequest decodeUserResponse

unaryCall : Cmd msg
unaryCall =
    Client.unary getUser { name = "Michal" }