View Source jarl (jarl v1.1.0)

Summary

Functions

Disconnects the client from the JSON-RPC server. The handler will receive a jarl_error message for all pending requests.

Sends a notification to the JSON-RPC server. It may return an error if the connection is not established and the request couldn't be sent.

Sends a result response to a JSON-RPC request. It may return an error if the connection is not established and the response couldn't be sent.

Sends an error response to a JSON-RPC request. It may return an error if the connection is not established and the response couldn't be sent.

Sends a synchronous request to the JSON-RPC server.

Sends an asynchronous request to the JSON-RPC server. The request is sent without waiting for a response. It may return an error if the connection is not established and the request couldn't be sent, but the handler will receive the jarl_error message anyway.

Starts a new JSON-RPC client connection process and links it to the calling process.

Types

error_mapping/0

-type error_mapping() :: {atom(), integer(), binary()}.

handler_messages/0

-type handler_messages() ::
          {jarl, pid(), {connected, Headers :: [{binary(), iodata()}]}} |
          {jarl, pid(), {request, method(), Params :: map() | list(), ReqRef :: binary() | integer()}} |
          {jarl, pid(), {notification, method(), Params :: map() | list()}} |
          {jarl, pid(), {result, Result :: term(), Ctx :: term()}} |
          {jarl,
           pid(),
           {error,
            Code :: integer() | atom(),
            Message :: undefined | binary(),
            ErData :: term(),
            Ctx :: term()}} |
          {jarl, pid(), {jarl_error, Reason :: jarl_error_reason(), Ctx :: term()}}.

jarl_error_reason/0

-type jarl_error_reason() :: not_connected | timeout | closed.

method/0

-type method() :: atom() | binary() | [atom() | binary()].

start_options/0

-type start_options() ::
          #{domain := atom() | string() | binary(),
            port := inet:port_number(),
            transport := tcp | tls | {tls, TlsOpts :: list()},
            path := atom() | string() | binary(),
            errors => [error_mapping()],
            ping_timeout => infinity | pos_integer(),
            request_timeout => infinity | pos_integer(),
            headers => [{binary(), iodata()}],
            protocols => [binary()]}.

Functions

disconnect(Conn)

-spec disconnect(Conn :: pid()) -> ok.

Disconnects the client from the JSON-RPC server. The handler will receive a jarl_error message for all pending requests.

notify(Conn, Method, Params)

-spec notify(Conn :: pid(), Method :: method(), Params :: map()) -> ok | {jarl_error, not_connected}.

Sends a notification to the JSON-RPC server. It may return an error if the connection is not established and the request couldn't be sent.

reply(Conn, Result, ReqRef)

-spec reply(Conn :: pid(), Result :: any(), ReqRef :: binary()) -> ok | {jarl_error, not_connected}.

Sends a result response to a JSON-RPC request. It may return an error if the connection is not established and the response couldn't be sent.

reply(Conn, Code, Message, ErData, ReqRef)

-spec reply(Conn :: pid(),
            Code :: atom() | integer(),
            Message :: undefined | binary(),
            ErData :: term(),
            ReqRef :: undefined | binary()) ->
               ok | {jarl_error, not_connected}.

Sends an error response to a JSON-RPC request. It may return an error if the connection is not established and the response couldn't be sent.

request(Conn, Method, Params)

-spec request(Conn :: pid(), Method :: method(), Params :: map()) ->
                 {result, Result :: term()} |
                 {error, Code :: integer(), Message :: undefined | binary(), ErData :: term()} |
                 {jarl_error, Reason :: jarl_error_reason()}.

Sends a synchronous request to the JSON-RPC server.

request(Conn, Method, Params, ReqCtx)

-spec request(Conn :: pid(), Method :: method(), Params :: map(), ReqCtx :: term()) ->
                 ok | {jarl_error, Reason :: jarl_error_reason()}.

Sends an asynchronous request to the JSON-RPC server. The request is sent without waiting for a response. It may return an error if the connection is not established and the request couldn't be sent, but the handler will receive the jarl_error message anyway.

start_link(Handler, Options)

-spec start_link(Handler :: pid(), Options :: start_options()) ->
                    {ok, Conn :: pid()} | {error, Reason :: term()}.

Starts a new JSON-RPC client connection process and links it to the calling process.