Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New docs for json views in Phoenix #341

Open
snewcomer opened this issue Oct 14, 2024 · 0 comments
Open

New docs for json views in Phoenix #341

snewcomer opened this issue Oct 14, 2024 · 0 comments

Comments

@snewcomer
Copy link
Contributor

Do we need new docs? Sry its been a while since I've looked at Phoenix, but with this new paradigm, it seems like we would make use of the Serializer?

https://hexdocs.pm/phoenix/json_and_apis.html

The usage docs

defmodule MyApp.PostView do
  use JSONAPI.View, type: "posts"

  def fields do
    [:text, :body, :excerpt]
  end

The default blueprint json file generated from mix.

defmodule MyApp.PostJSON do
  @doc """
  Renders a list of posts.
  """
  def index(%{posts: posts}) do
    %{data: for(post <- posts, do: data(post))}
  end

  @doc """
  Renders a single post.
  """
  def show(%{post: post}) do
    %{data: data(post)}
  end

  defp data(%Post{} = post) do
    %{
      id: post,
      text: post.text
    }
  end
end
@snewcomer snewcomer changed the title New docs for New docs for json views in Phoenix Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant