Skir.RPC.Service (skir_elixir_client v0.2.2)

Copy Markdown View Source

In-process SkirRPC dispatcher.

handle_request/3 accepts the raw SkirRPC payload used by both POST bodies and decoded GET query strings, and returns a transport-neutral RawResponse.

Summary

Functions

Registers a method and an arity-2 handler receiving the decoded request and metadata. Duplicate method numbers raise ArgumentError.

Dispatches a raw SkirRPC payload, list, or studio and returns a Skir.RPC.RawResponse. Metadata is passed to the handler.

Creates a service. Options configure unknown fields, error disclosure/logging, Studio, and request size.

Controls whether internal error messages reach clients, using a boolean or an ErrorInfo predicate. Default: hidden.

Sets the callback receiving Skir.RPC.ErrorInfo for controlled and unknown handler failures.

Controls preservation of unknown request fields. Enable only at trusted forwarding boundaries.

Sets the maximum raw request size in bytes. The default is 4,194,304.

Sets the JavaScript URL loaded by the RPC Studio page.

Types

handler()

@type handler() :: (term(), term() ->
                {:ok, term()}
                | {:error,
                   Skir.RPC.ServiceError.t() | Skir.RPC.UnknownError.t()})

t()

@type t() :: %Skir.RPC.Service{
  by_number: term(),
  can_send_unknown_error_message: term(),
  error_logger: term(),
  keep_unrecognized_values: term(),
  max_request_bytes: term(),
  studio_app_js_url: term()
}

Functions

add_method(service, method, handler)

@spec add_method(t(), Skir.Method.t(), handler()) :: t()

Registers a method and an arity-2 handler receiving the decoded request and metadata. Duplicate method numbers raise ArgumentError.

handle_request(service, body, request_metadata \\ nil)

@spec handle_request(t(), binary(), term()) :: Skir.RPC.RawResponse.t()

Dispatches a raw SkirRPC payload, list, or studio and returns a Skir.RPC.RawResponse. Metadata is passed to the handler.

new(opts \\ [])

@spec new(keyword()) :: t()

Creates a service. Options configure unknown fields, error disclosure/logging, Studio, and request size.

set_can_send_unknown_error_message(service, value)

@spec set_can_send_unknown_error_message(
  t(),
  boolean() | (Skir.RPC.ErrorInfo.t() -> boolean())
) :: t()

Controls whether internal error messages reach clients, using a boolean or an ErrorInfo predicate. Default: hidden.

set_error_logger(service, fun)

@spec set_error_logger(t(), (Skir.RPC.ErrorInfo.t() -> term())) :: t()

Sets the callback receiving Skir.RPC.ErrorInfo for controlled and unknown handler failures.

set_keep_unrecognized_values(service, value)

@spec set_keep_unrecognized_values(t(), boolean()) :: t()

Controls preservation of unknown request fields. Enable only at trusted forwarding boundaries.

set_max_request_bytes(service, value)

@spec set_max_request_bytes(t(), pos_integer()) :: t()

Sets the maximum raw request size in bytes. The default is 4,194,304.

set_studio_app_js_url(service, url)

@spec set_studio_app_js_url(t(), String.t()) :: t()

Sets the JavaScript URL loaded by the RPC Studio page.