JaSerializer.PhoenixView
Use in your Phoenix view to render jsonapi.org spec json.
See JaSerializer.Serializer for documentation on defining your serializer.
Usage example
defmodule PhoenixExample.ArticlesView do
use PhoenixExample.Web, :view
use JaSerializer.PhoenixView # Or use in web/web.ex
attributes [:title]
end
defmodule PhoenixExample.ArticlesController do
use PhoenixExample.Web, :controller
def index(conn, _params) do
render conn, model: PhoenixExample.Repo.all(PhoenixExample.Article)
end
def show(conn, params) do
render conn, model: PhoenixExample.Repo.get(PhoenixExample.Article, params[:id])
end
end
Summary
render(serializer, data) | Extracts the model and opts from the data passed to render and returns result of formatting |
render_and_serialize(serializer, data) | Calls render/2 then encodes the result with the JSON encoder defined in phoenix config |
Functions
Extracts the model and opts from the data passed to render and returns result of formatting.
Calls render/2 then encodes the result with the JSON encoder defined in phoenix config.