# `AshToonEx.Phoenix.ToonSerializer`
[🔗](https://github.com/ohhi-vn/ash_toon_ex/blob/v0.3.0/lib/ash_toon_ex/phoenix/toon_serializer.ex#L5)

Phoenix serializer for TOON format.

This module provides helper functions to use TOON format in Phoenix controllers.

## Usage

In your Phoenix controller:

    def show(conn, %{"id" => id}) do
      resource = MyResource |> Ash.get!(id)
      conn
      |> put_resp_content_type("application/x-toon")
      |> send_resp(200, ToonEx.encode!(resource))
    end

You can also use it with `render/3` by encoding manually.

# `decode`

Decodes TOON format string to Elixir data.

## Examples

    iex> AshToonEx.Phoenix.ToonSerializer.decode("name: Alice
age: 30")
    %{"name" => "Alice", "age" => 30}

# `decode_btoon`

Decodes BTOON binary format to Elixir data.

## Examples

    iex> AshToonEx.Phoenix.ToonSerializer.decode_btoon(<<...>>)
    %{"name" => "Alice", "age" => 30}

# `encode`

Encodes data to TOON format string.

## Examples

    iex> AshToonEx.Phoenix.ToonSerializer.encode(%{name: "Alice", age: 30})
    "age: 30
name: Alice"

# `encode_btoon`

Encodes data to BTOON binary format.

## Examples

    iex> AshToonEx.Phoenix.ToonSerializer.encode_btoon(%{name: "Alice", age: 30})
    <<...>>

---

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