# `WardrikDaemon.Client`

Reaches a daemon over its HTTP API. The `wardrik` command uses it.

    client = %WardrikDaemon.Client{url: "http://127.0.0.1:4747", secret: secret}
    {:ok, answer} = WardrikDaemon.Client.run(client, "agents.list", %{})

Each `WardrikProtocol` operation is sent to its route, with `secret` as the bearer token.

# `error`

```elixir
@type error() :: {:error, String.t(), String.t()}
```

Why an operation failed: the protocol's error type, and its message.

# `t`

```elixir
@type t() :: %WardrikDaemon.Client{
  req_options: keyword(),
  secret: String.t(),
  url: String.t()
}
```

# `close`

```elixir
@spec close(Req.Response.t()) :: :ok
```

Stops reading an opened stream.

# `next`

```elixir
@spec next(Req.Response.t(), timeout()) ::
  {:ok, [map()], Req.Response.t()} | :done | :timeout
```

Returns the next events on an opened stream. Waits at most `timeout`. Returns `:done` once the stream ends.

# `open`

```elixir
@spec open(t(), String.t(), map()) :: {:ok, Req.Response.t()} | error()
```

Opens the operation `id`'s events as server-sent events. Read them with `next/2`.

It returns once the daemon is following them, so nothing written after it returns is missed.

# `run`

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

Runs the operation `id` with `input`. Returns its answer, or `nil` if it answers nothing.

---

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