# `Electric.Client.ShapeKey`
[🔗](https://github.com/electric-sql/electric/tree/%40core/elixir-client%400.10.2/packages/elixir-client/lib/electric/client/shape_key.ex#L1)

Generate canonical shape keys for cache lookup.

The canonical shape key is a stable identifier for a shape definition that
excludes Electric protocol parameters (like cursor, handle, offset, etc.).
This allows the client to identify when different requests are for the same
underlying shape, which is useful for cache busting when CDN/proxy caches
serve stale responses.

# `canonical`

```elixir
@spec canonical(URI.t()) :: String.t()
```

Generate a canonical shape key from a URI.

Extracts query parameters, filters out Electric protocol parameters,
sorts the remaining parameters alphabetically, and returns a canonical
URL string.

## Examples

    iex> uri = URI.parse("http://localhost:3000/v1/shape?table=items&cursor=123&offset=0_0")
    iex> ShapeKey.canonical(uri)
    "http://localhost:3000/v1/shape?table=items"

# `canonical`

```elixir
@spec canonical(URI.t(), map()) :: String.t()
```

Generate a canonical shape key from an endpoint URI and params map.

## Examples

    iex> endpoint = URI.parse("http://localhost:3000/v1/shape")
    iex> params = %{"table" => "items", "where" => "id > 0", "offset" => "0_0"}
    iex> ShapeKey.canonical(endpoint, params)
    "http://localhost:3000/v1/shape?table=items&where=id%20%3E%200"

---

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