# `BankingCircle.HTTP.Middleware.Idempotency`
[🔗](https://github.com/iamkanishka/banking_circle/blob/main/lib/banking_circle/http/middleware/idempotency.ex#L1)

Attaches an `Idempotency-Key` header to a request, either from a caller
supplied value or a generated UUIDv4.

As of this writing, Banking Circle documents idempotency-key support
specifically for **Direct Debit Collections** endpoints, with a note that
other payment operations are planned to align with the same pattern
later. Attaching the header on unsupported endpoints is harmless (it will
simply be ignored), but callers should not *rely* on idempotency
protection outside the documented scope — check `BankingCircle.Payments`
function docs for per-endpoint guidance before assuming a blind retry is
safe.

A replayed key returns HTTP 400 with a body identifying the original
acceptance; `BankingCircle.Error.parse/2` normalizes that like any other
error.

# `attach`

```elixir
@spec attach(Req.Request.t(), String.t() | nil) :: Req.Request.t()
```

# `generate_key`

```elixir
@spec generate_key() :: String.t()
```

Generates a UUIDv4 suitable for use as an idempotency key.

---

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