# `Sigra.RateLimiter`
[🔗](https://github.com/sztheory/sigra/blob/v1.20.0/lib/sigra/rate_limiter.ex#L1)

Behaviour for rate limiting implementations.

Sigra supports both IP-based and account-based rate limiting. When
Hammer is available, `Sigra.RateLimiters.Hammer` provides the
implementation. When Hammer is absent, `Sigra.RateLimiters.Noop`
is used as a fail-open fallback with a logged warning.

## Return Values

Rate limiters return tagged tuples following Hammer's convention:

- `{:allow, count}` -- request allowed, `count` is the current request count
- `{:deny, retry_after_ms}` -- request denied, `retry_after_ms` indicates when to retry

## Mox Usage

    Mox.defmock(MockRateLimiter, for: Sigra.RateLimiter)

# `check_rate`
*since 0.1.0* 

```elixir
@callback check_rate(
  key :: String.t(),
  limit :: pos_integer(),
  window_ms :: pos_integer()
) ::
  {:allow, count :: pos_integer()} | {:deny, retry_after_ms :: pos_integer()}
```

Checks whether a request identified by `key` should be allowed.

---

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