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))
endYou 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
Decodes TOON format string to Elixir data.
Examples
iex> AshToonEx.Phoenix.ToonSerializer.decode("name: Aliceage: 30")
%{"name" => "Alice", "age" => 30}
Decodes BTOON binary format to Elixir data.
Examples
iex> AshToonEx.Phoenix.ToonSerializer.decode_btoon(<<...>>)
%{"name" => "Alice", "age" => 30}
Encodes data to TOON format string.
Examples
iex> AshToonEx.Phoenix.ToonSerializer.encode(%{name: "Alice", age: 30})
"age: 30name: Alice"
Encodes data to BTOON binary format.
Examples
iex> AshToonEx.Phoenix.ToonSerializer.encode_btoon(%{name: "Alice", age: 30})
<<...>>