Skip to content

elixir-ts-rpcTyped RPC, Elixir โ†” TypeScript

Your Elixir functions callable from TypeScript. The function is the contract.

See it run โ€‹

A guided tour of the playground. Edit a @spec, watch the client regenerate, follow a method back to the handler that produced it, then rename a field and watch the TypeScript break. That is the real codegen running in the browser, compiled to WebAssembly. Try it yourself โ†’

How it looks โ€‹

A procedure is an ordinary function. Its @spec is how you tell the compiler its shape today:

elixir
defmodule MyApp.Users do
  use RpcElixir.Handler

  @spec get(%{id: String.t()}, RpcElixir.Context.t()) ::
          {:ok, %{id: String.t(), email: String.t()}} | {:error, :not_found}
  def get(%{id: id}, _ctx), do: ...
end

Expose the module on a router:

elixir
scope "users" do
  expose MyApp.Users   # โ†’ "users.get", "users.list", โ€ฆ
end

Run mix rpc.gen.ts, then call it from the browser:

ts
const 
user
= await
client
.
users
.
get
({
id
: "u_1" });
const
email
=
user
.
email
;

Get started โ†’