superlistapp / ferryman_ex

A pure Elixir JSONRPC2 Client & Server realization with Redix.

Home Page:https://hexdocs.pm/ferryman_ex/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

⚡️ FerrymanEx

CI Hex.pm docs

FerrymanEx is a pure Elixir JSONRPC2 Client & Server realization.

Ferryman is a JSONRPC 2.0 Client & Server realization for Erlang and Ruby.

💻 Installation

def deps do
  [
    {:ferryman_ex, github: "superlistapp/ferryman_ex"}
  ]
end

🚀 Getting Started

To get started, make sure you have a running instance of Redis.

FerrymanEx uses Redix as redis driver.

You can start a local redis instance by running docker run --name my-redis -p 6379:6379 -d redis

Server

First, let's define a JSONRPC2 handler, and define the functions we want to be handled by RPC calls.

defmodule ExampleHandler do
  use JSONRPC2.Server.Handler

  def handle_request("add", [x, y]) do
    x + y
  end
end

Now we can start our Ferryman Server.

iex> {:ok, pid} = Ferryman.Server.start_link(redis_config: [], channels: ["mychannel"], handler: ExampleHandler)

The default redis_config will look for a redis instance on "localhost:6379". For more configuration options, please check the Redix Docs.

You can define a list of channels, and pass the handler module.

Client

To start communicating with the Ferryman server, let's first start our redis process:

iex> {:ok, redis} = Redix.start_link()

Now we can simply call the functions, the server has implemented:

iex> Ferryman.Client.call(redis, "mychannel", "add", [1, 2])
{:ok, 3}

🤓 Used Libraries

Redix Jason JSONRPC2

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) 2022 Superlist

About

A pure Elixir JSONRPC2 Client & Server realization with Redix.

https://hexdocs.pm/ferryman_ex/

License:MIT License


Languages

Language:Elixir 100.0%