# `ZenWebsocket.JsonRpc`
[🔗](https://github.com/ZenHive/zen_websocket/blob/v0.4.2/lib/zen_websocket/json_rpc.ex#L1)

JSON-RPC 2.0 request builder and response matcher.

Simple API builder for WebSocket APIs using JSON-RPC 2.0 protocol.
Generates request functions with automatic ID tracking and correlation.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `match_response` | 1 | Match a JSON-RPC response as result, error, or notification. | `response: value` |
| `build_request` | 2 | Build a JSON-RPC 2.0 request with unique ID. | `method: value`, `params: value` |

# `__using__`
*macro* 

Imports the `defrpc/2` and `defrpc/3` macros for defining JSON-RPC methods.

# `build_request`

```elixir
@spec build_request(String.t(), map() | nil) :: {:ok, map()}
```

Builds a JSON-RPC 2.0 request with unique ID.

## Examples
    iex> {:ok, request} = JsonRpc.build_request("public/auth", %{grant_type: "client_credentials"})
    iex> request["method"]
    "public/auth"

# `defrpc`
*macro* 

Generates RPC method functions with automatic request building.

## Examples
    defmodule MyApi do
      use ZenWebsocket.JsonRpc

      defrpc :authenticate, "public/auth"
      defrpc :subscribe, "public/subscribe"
      defrpc :get_order_book, "public/get_order_book"
    end

# `match_response`

```elixir
@spec match_response(map()) ::
  {:ok, term()}
  | {:error, {integer(), String.t()}}
  | {:notification, String.t(), map()}
```

Matches a JSON-RPC response to determine if it's a result or error.

Returns:
- `{:ok, result}` for successful responses
- `{:error, {code, message}}` for JSON-RPC errors
- `{:notification, method, params}` for notifications

---

*Consult [api-reference.md](api-reference.md) for complete listing*
