AshToonEx.Phoenix.ToonSerializer (ash_toon_ex v0.3.0)

Copy Markdown View Source

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.

Summary

Functions

Decodes TOON format string to Elixir data.

Decodes BTOON binary format to Elixir data.

Encodes data to TOON format string.

Encodes data to BTOON binary format.

Functions

decode(toon_string, opts \\ [])

Decodes TOON format string to Elixir data.

Examples

iex> AshToonEx.Phoenix.ToonSerializer.decode("name: Alice

age: 30")

%{"name" => "Alice", "age" => 30}

decode_btoon(btoon_binary, opts \\ [])

Decodes BTOON binary format to Elixir data.

Examples

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

encode(data, opts \\ [])

Encodes data to TOON format string.

Examples

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

name: Alice"

encode_btoon(data, opts \\ [])

Encodes data to BTOON binary format.

Examples

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