# `Macaw.Component.Proxy`
[🔗](https://github.com/dcoai/macaw_component/blob/v0.13.0/lib/macaw/component/proxy.ex#L1)

Proxy routes (spec/01 §1.8): media a component needs from another origin, fetched by the
host's one same-origin proxy, so a page holds same-origin URLs only.

    iex> route = %{name: "tiles", url: "https://tiles.example/{z}/{x}/{y}.png", types: ["image/png"]}
    iex> {:ok, digest} = Macaw.Component.Proxy.digest(route)
    iex> Macaw.Component.Proxy.path("geo.map", route, %{"z" => "1", "x" => "0", "y" => "0"}) ==
    ...>   {:ok, "/macaw/proxy/geo.map/tiles/#{digest}?x=0&y=0&z=1"}
    true

# `route`

```elixir
@type route() :: %{name: String.t(), url: String.t(), types: [String.t(), ...]}
```

# `digest`

```elixir
@spec digest(route()) :: {:ok, String.t()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

A route's digest (spec/01 §1.8): the first 16 hex digits of
`Macaw.Base.Encoding.digest/1` of `{url, types}`, so two routes of one name with
different templates or types have different digests. Types that are not data are
`{:error, faults}`, as `Encoding.digest/1` answers them.

    iex> Macaw.Component.Proxy.digest(%{name: "t", url: "https://a.example/{z}", types: ["image/png"]})
    ...> |> elem(1) |> String.length()
    16

# `path`

```elixir
@spec path(String.t(), route(), %{required(String.t()) =&gt; String.t()}) ::
  {:ok, String.t()}
  | {:error,
     {:placeholders, [String.t(), ...]} | {:bad_route, [Macaw.Base.Fault.t()]}}
```

The same-origin path a render uses for a route of a component:
`/macaw/proxy/<component>/<route>/<digest>?<values>`, the route's `digest/1`, the values
query-encoded in name order. Every placeholder needs a value:
`{:error, {:placeholders, missing}}` otherwise; a route whose types aren't data is
`{:error, {:bad_route, faults}}`.

# `placeholders`

```elixir
@spec placeholders(route()) :: [String.t()]
```

The placeholders a route's URL template names, in order of first appearance.

---

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