# `HttpDouble.MockRule`
[🔗](https://github.com/aszymanskiit/http_double/blob/main/lib/http_double/mock_rule.ex#L1)

Representation of a mock or expectation rule for HTTP requests.

Rules are evaluated by `HttpDouble.MockEngine` and can match on method, path,
host, query, headers, body, connection id and call index, or use arbitrary
predicate functions.

# `kind`

```elixir
@type kind() :: :stub | :expect
```

Rule kind.

# `meta`

```elixir
@type meta() :: %{conn_id: non_neg_integer(), call_index: non_neg_integer()}
```

Metadata provided to predicate functions and callbacks.

# `t`

```elixir
@type t() :: %HttpDouble.MockRule{
  call_range: Range.t() | nil,
  conn_ids: [non_neg_integer()] | nil,
  id: reference(),
  kind: kind(),
  matcher: term(),
  max_calls: :infinity | non_neg_integer(),
  respond: HttpDouble.response_spec(),
  times_used: non_neg_integer()
}
```

Internal struct type.

# `build`

```elixir
@spec build(kind(), Keyword.t()) :: t()
```

Builds a rule from a keyword options list.

Supported options:

  * `:matcher` – see `t:HttpDouble.matcher/0`
  * `:respond` – response specification
  * `:conn_id` / `:conn_ids` – restrict to specific connection(s)
  * `:call_range` – restrict to a specific range of call indices
  * `:max_calls` – maximum number of times the rule may match

# `meta_from_request`

```elixir
@spec meta_from_request(HttpDouble.Request.t(), non_neg_integer() | nil) :: meta()
```

Produces metadata from a request and optional call index.

---

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